A good memory is better than a pen.
Examples of character streams with buffer areas
Package com.
Ckinghan.outputstream;
Import Java.io.BufferedInputStream;
Import Java.io.BufferedOutputStream;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.OutputStream; /** * * @author Ckinghan * Description: Byte stream with efficient buffer * * public class Bufferedinputstreamdemo {public static void main (St
Ring[] args {/** * Read the copied file using a byte stream with an efficient buffer, copy: Copy one character at a time/bufferedinputstreamreader ();
/** * Read the copied file in a byte stream with an efficient buffer, copying: Copy the specified number of bytes at a time/bufferedinputstreamcopyfile (); /** * @ Description: Read the copied file using a byte stream with an efficient buffer, copy by: Copy the specified number of bytes at a time: */public static void Bufferedinputstreamco
Pyfile () {///create byte stream object InputStream inputstream = null;
OutputStream outputstream = null; try {//instantiated efficient buffer byte stream input, output object InputStream = new Bufferedinputstream (New FileinputstreAM ("E:/weblogin.log"));
OutputStream = new Bufferedoutputstream (New FileOutputStream ("E:/new.log"));
The number of file bytes per read int len =-1;
Each read the file byte data byte[] bs = new byte[1024]; Iterate through the file until it is read to the end of the file while (len = Inputstream.read (BS))!=-1 {//write to file outputs
Tream.write (BS, 0, Len);
//empty buffer to save the data written to the file Outputstream.flush ();
Replication Successful output System.out.println ("Use efficient buffer byte to read a specified number of bytes at a time to copy files completed");
catch (FileNotFoundException e) {e.printstacktrace ();
catch (IOException e) {e.printstacktrace (); }finally {try {//close stream if (outputstream!= null) outputstre
Am.close ();
if (InputStream!= null) inputstream.close ();
catch (IOException E2) {e2.printstacktrace (); /** * @ Description: Read the copied file using a byte stream with an efficient buffer copy: Copy one character at a time * @ Created:/public static VO
ID Bufferedinputstreamreader () {///create byte stream object InputStream inputstream = null;
OutputStream outputstream = null; try {//instantiate efficient buffer byte stream input, output object InputStream = new Bufferedinputstream (New FileInputStream ("E:/weblogin
. log "));
OutputStream = new Bufferedoutputstream (New FileOutputStream ("E:/login.log"));
Bytes read acsii code int val =-1; Iterate through the file until it is read to the end of the file while ((val = Inputstream.read ())!=-1) {//write to file Outputstrea
M.write (Val);
//empty buffer to save the data written to the file Outputstream.flush ();
Copy successfully output SYSTEM.OUT.PRINTLN ("read one byte at a time with efficient buffer stream copy file complete");
catch (FileNotFoundException e) {e.printstacktrace ();
catch (IOException e) {e.printstacktrace ();Finally {try {//close stream if (outputstream!= null) outputstr
Eam.close ();
if (InputStream!= null) inputstream.close ();
catch (IOException E2) {e2.printstacktrace ();
}
}
}
}