Input stream:
public void inputDemo () throws IOException {
// file name String fileName = " D: \\ aaa.txt " ;
// Create a file object by file name File File = new new File (fileName);
// Create a stream object input
/ / new new a FileOutputStream (File); the FileInputStream FIS = new new the FileInputStream (fileName); // int C; // the while ((C = fis.read ())> 0) { // of System.out.print ((char) C ); // } // create a byte array byte [] = buf new new byte [ 2000 ]; Int len;
// no content found returns -1, it is judged that there is no content. There are then output the while ((len = fis.read (buf))> 0 ) { the System. OUT .println ( " New glass: " ); . The System OUT .println ( new new String (buf)); } // Close input stream fis.close (); }
Output stream:
public void outputDemo () throws IOException {
// create output target stream a FileOutputStream fos = new new a FileOutputStream ( " D: \\ named bbb.txt " );
// create output stream through writing the OutputStreamWriter Writer = new new the OutputStreamWriter (fos);
// written by writing the contents of the stream writer.Write ( " Hello, Output stream " ); writer.Close (); }