Java Io flows to specified file input content, javaio
Package com. hp. io;
Import java. io .*;
Public class BufferedWriterTest {
Public static void main (String args []) {
FileWriter fw = null;
BufferedWriter bw = null; // buffer output
FileReader fr = null;
BufferedReader bw = null; // buffer input
Try {
Fw = new FileWriter ("f :\\ discard bar .txt"); // file to be written
Bw = new BufferedWriter (fw); // Save the input content in the buffer zone.
Bw. write ("HelloWorld"); // write content
Bw. newLine (); // change the line
Bw. write ("Hello, world ");
Bw. newLine ();
Bw. flush (); // refresh the buffer
// Read the content in the buffer
Fr = new FileReader ("f :\\ discard folder .txt"); // be sure to keep the file name consistent with the one you write.
Br = new BufferedReader (fr); // read the buffer content
String line = br. readLine ();
While (line! = Null ){
System. out. print (line );
Line = br. readLine ();
}
Fr. close (); // close the data stream
} Catch (IOException e ){
System. out. print ("the file does not exist ");
} Finally {
Try {
If (fw! = Null)
Fw. close ();
If (br! = Null)
Br. close ();
If (fr! = Null)
Fr. close ();
} Catch (IOExeption e ){
E. printStackTrace ();
}
}
}
}