Io flow simply means that the input stream and output stream are primarily used to process data transfer between devices
Case 1 is a byte stream, Case 2 is a character stream, the difference between the byte stream and the character stream is very large, and the reader needs to use it according to his own scene.
Case 1:
Use byte stream and package stream (readers can understand the packaging flow, mainly using the adorner mode) to read and write files.
Public classFileCopy { Public Static voidCopyFile (File src,file Res)throwsexception{InputStream in=NewBufferedinputstream (NewFileInputStream (SRC)); OutputStream out=NewBufferedoutputstream (NewFileOutputStream (res)); byte[] bt=New byte[1024]; while( -1!=(In.read (BT))) {Out.write (BT,0, bt.length); } out.flush (); Out.close (); In.close (); } Public Static voidMain (string[] args) {File src=NewFile ("D:/tmp/test.xls"); File Res=NewFile ("D:/tmp/b.xls"); Try{copyfile (src, res); } Catch(Exception e) {e.printstacktrace (); } }}
Case 2:
File read and write using wrapper stream and character stream
Public classFileCopy { Public Static voidMain (string[] args)throwsException {bufferedreader br=NewBufferedReader (NewInputStreamReader (NewBufferedinputstream (NewFileInputStream (NewFile ("D:/tmp/a.txt")), "GBK")); BufferedWriter out=NewBufferedWriter (NewOutputStreamWriter (NewBufferedoutputstream (NewFileOutputStream (NewFile ("D:/tmp/b.txt")), "GBK")); String Line=NULL; while(NULL! = (line=Br.readline ())) {Out.write (line); Out.newline (); } out.flush (); Out.close (); Br.close (); }}
Java file read/write