Features of Bufferinputstream and Bufferoutputstream:
Buffered bytes input and output stream, buffer stream is a processing stream, it does not directly connect to the data source/destination, but a byte stream as a parameter, on the basis of the node flow to provide some simple operation.
First of all, the principle of non-buffered flow, it reads to a byte/character, to the user-specified path to write out, read a write one, so slow, with the buffer stream working principle, read to a byte/character, first output, and so on to fill the maximum capacity of the buffer once written out, thereby improving the efficiency.
Advantages: Reduce the number of hard disk reads, reduce the loss of the hard disk.
Report:
Import Java.io.BufferedReader;
Import Java.io.BufferedWriter;
Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileReader;
Import Java.io.FileWriter;
Import java.io.IOException;
Import Java.io.Reader;
Import Java.io.Writer;
/**
* Use BufferedReader and bufferedwriter to make copies of text files
* @author Administrator
*
*/
public class Bufferoperatestr {
public static void Main (string[] args) {
Copy ();
}
static void Copy () {
Reader reader = null;
BufferedReader br = null;
writer writer = null;
BufferedWriter bw = NULL;
try {
Part I: Preparing to read data from a file to a program
reader = new FileReader (New File ("D://a.txt"));
Create a buffered stream wrapper object reader
br = new BufferedReader (reader);
Part two: Preparing to write to a file from a program; writing to an object writer
writer = new FileWriter (New File ("D:\\a3.txt"));
Creating a buffered stream wrapper writer
BW = new BufferedWriter (writer);
String str = NULL;
Read and write with circular edges
while ((Str=br.readline ())!=null) {
Bw.write (str);
Bw.newline ();
}
Bw.flush (); emptying buffers
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}finally{
try {
if (bw!=null) {
Bw.close ();
}
if (br!=null) {
Br.close ();
}
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
}
Bufferinputstream, Bufferoutputstream, BufferedReader, BufferedWriter, Java code uses BufferedReader and bufferedwriter to make a copy of a text file