Home » Java » A program entry, IO stream. Based on the EcLipse m...

A program entry, IO stream. Based on the EcLipse mars.2 folder structure

a program entry, IO stream. Based on EcLipse mars.2 folder structure. There is a friend in need of reference.


import java.io.*;
Public, class, TestFileOutputStream {
Public, static, void, main (String[], args) {
Int read_returned = 0; / / public int based on API, read FileInputStream java.io.InputStream (), to accept the return value
FileInputStream input = null; / / initialize read stream
FileOutputStream output = null; / / initialize write stream
Try{
Input = new FileInputStream ("E:\sync\Java\TestFileInputStream\src\TestFileInputStream.java"); / / read the file path information set
Output = new FileOutputStream ("E:\sync\Java\TestFileOutputStream\autocopy.java"); / / set the write path information
While ((read_returned = input.read ()) = = -1) {
Output.write (read_returned); / / FileOutputStream based write (int b) method into a output object
}
(output.flush); / / empty data buffer, and then shut down
Input.close ();
Output.close ();
}catch (FileNotFoundException fnfe) for the treatment of abnormal {// do throw
System.out.println ("Can not find the file");
System.exit (-1);
}catch (IOException, IOE) {
System.out.println ("IO error");
System.exit (-1);
}
System.out.println ("File Copied.");
System.out.println ("The file content:");
Try{
Input = new FileInputStream ("E:\sync\Java\TestFileOutputStream\autocopy.java");
While ((read_returned = input.read ()) = = -1) {
System.out.print ((char) read_returned);
}
Input.close ();
}catch (IOException, IOE) {
System.out.println ("File reading error");
System.exit (-1);
}
}
}

Latest