Java Io flows to specified file input content, javaio

Source: Internet
Author: User

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 ();

}

}

}

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.