Tutorials to .com

Tutorials to .com » Jsp » Skills » java simple application of io

java simple application of io

Print View , by: iSee ,Total views: 37 ,Word Count: 461 ,Date: Mon, 24 Aug 2009 Time: 10:06 PM

java's io system is relatively large and complex, the general concept of it is also a feeling of novice is not very clear, I did a few simple examples to all of us want to have some help.

/ / Read data from the file, display on the screen
package com.yourcompany.core;

import java.io. *;

public class Think (

public static void main (String [] args) (

try (

FileInputStream file = new FileInputStream ( "d: \ \ sss.txt");
char [] c = new char [file.available ()];
for (int i = 0; i <c.length; i + +) (
C++ [i] = (char) file.read ();

)
System.out.print (c);

)
catch (FileNotFoundException e) (

e.printStackTrace ();
)
catch (IOException e) (

e.printStackTrace ();
)

)
)
/ / Write something on the screen to a file
package com.yourcompany.core;

import java.io. *;
import java.util .*;


public class Think (

public static void main (String [] args) (

try (

byte [] c = new byte [1000];
System.in.read (c);
FileOutputStream file = new FileOutputStream ( "d: \ \ s.txt");
file.write (c);
)
catch (Exception e) (
e.printStackTrace ();
)
)
)
/ / From one file to another file
package com.yourcompany.core;

import java.io. *;
import java.util .*;


public class Think (

public static void main (String [] args) (

try (

FileInputStream file = new FileInputStream ( "d: \ \ sss.txt");
FileOutputStream fileout = new FileOutputStream ( "d: \ \ aaa.txt");
byte [] c = new byte [file.available ()];
for (int i = 0; i <c.length; i + +) (
c [i] = (byte) file.read ();
)
fileout.write (c);
)
catch (Exception e) (
e.printStackTrace ();
)
)
)
/ / On the screen what you type what I type
package com.yourcompany.core;

import java.io. *;
import java.util .*;


public class Think (

public static void main (String [] args) (

try (

byte [] c = new byte [1000];
int cc = System.in.read (c);
for (int i = 0; i <cc; i + +) (
System.out.print ((char) c [i]);
)
)
catch (Exception e) (
e.printStackTrace ();
)

)
)




Java skills and code Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.