Buffered character Stream Bufferedinputstream/bufferedoutputstream
File Operation Flow Inputstream/outputstream
The socket of the Java input and output stream, test the speed of the flow chain
Because the node flow is not very common in the program, usually through the filter flow to connect multiple flows together, using the characteristics of each flow to work together the data, the multiple flows of the socket constitute a flow chain;
Let's analyze their running time. (because the time may vary on different systems (Maxox,linux,win (32/64)), I've been intercepting it for a few days to compare.
1. buffered character Stream Bufferedinputstream/bufferedoutputstream
Import Java.io.bufferedinputstream;import Java.io.bufferedoutputstream;import java.io.file;import Java.io.fileinputstream;import Java.io.fileoutputstream;import java.io.IOException; Public classMain { Public Static voidMain (string[] args) throws IOException {LongStartTime =System.nanotime (); File Address=NewFile ("D:"+file.separator+"C.txt"); File Address1=NewFile ("D:"+file.separator+"Ww.txt"); Bufferedinputstream bin=NewBufferedinputstream (NewFileInputStream (address)); Bufferedoutputstream bout=NewBufferedoutputstream (NewFileOutputStream (Address1)); intC; while((C=bin.read ())!=-1) {bout.write (c); } bin.close (); Bout.flush (); Bout.close (); System. out. println ("Copy Complete"); LongEndTime =System.nanotime (); System. out. println ((endtime-starttime) +"Ms"); }}
2. file operation Flow Inputstream/outputstream
ImportJava.io.File;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream; Public classMain { Public Static voidMain (string[] args)throwsIOException {LongStartTime =System.nanotime (); File Address=NewFile ("D:" +file.separator+ "C.txt"); File Address1=NewFile ("D:" +file.separator+ "Ww.txt"); InputStream in=NewFileInputStream (address); OutputStream out=NewFileOutputStream (ADDRESS1); intC; while((C=in.read ())!=-1) {out.write (c); } in.close (); Out.flush (); Out.close (); System.out.println ("Copy Complete"); LongEndTime =System.nanotime (); System.out.println ((EndTime-starttime) + "MS"); }}
3.sockets for Java input and output streams
ImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.DataInputStream;ImportJava.io.DataOutputStream;ImportJava.io.File;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream; Public classMain { Public Static voidMain (string[] args)throwsIOException {LongStartTime =System.nanotime (); File Address=NewFile ("D:" +file.separator+ "C.txt"); File Address1=NewFile ("D:" +file.separator+ "Ww.txt"); Bufferedinputstream bin=NewBufferedinputstream (NewFileInputStream (address)); Bufferedoutputstream bout=NewBufferedoutputstream (NewFileOutputStream (Address1)); InputStream din=NewDataInputStream (BIN); OutputStream dout=Newdataoutputstream (bout); intC; while((c = din.read ())!=-1) {dout.write (c); } bin.close (); Bout.flush (); Bout.close (); Din.close (); Dout.flush (); Dout.close (); System.out.println ("Copy succeeded"); LongEndTime =System.nanotime (); System.out.println ((EndTime-starttime) + "MS"); }}
Their uptime is somewhat similar because they read only one character at a time and then write to the file.
Their use needs to look at the scene selection:
Select FileInputStream class for normal file input and output
Select the buffering class when faster input and output is required
Selecting a socket for the Java input and output stream at multiple inputs and outputs makes it easy to process data and improve processing efficiency.
Sockets for Java IO input/output streams