Java programming --- io stream reads the file content and outputs its inverse value to the console, java --- io

Source: Internet
Author: User

Java programming --- io stream reads the file content and outputs its inverse value to the console, java --- io

Import java. io. BufferedReader;
Import java. io. BufferedWriter;
Import java. io. File;
Import java. io. FileReader;
Import java. io. OutputStreamWriter;

Public class inverse value {
/*

;

*/
Public static void main (String [] args) throws Exception {
// TODO Auto-generated method stub
File file = new File ("Demo \ Integrated Application \ copy.txt ");
BufferedReader br = new BufferedReader (new FileReader (file ));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System. out ));
String str;
StringBuffer Str = new StringBuffer ("");// Create a variable string format. It cannot be declared directly. If it is declared directly, a null pointer exception occurs;
While (str = br. readLine ())! = Null ){
Str. append (str );// Add the content read each time to the end of the variable string;
}
Str. reverse ();// Reduce the reverse value of a variable string;
Str = Str. toString (); // Convert a variable string to a normal string, because write () can only output string-type parameters
Bw. write (str );
Bw. flush ();
Bw. close ();
}

}

 

Hope to help everyone!

All rights reserved. for forwarding, please contact the blogger!

 

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.