Java Programming---IO stream reads the contents of the file and outputs its inverse value to the console

Source: Internet
Author: User
Tags string format

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

public class Inverse Value {
/*

*2017-07-01;

*/
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 variable string format, can not directly declare, direct declaration will produce null pointer exception;
while ((Str=br.readline ())!=null) {
str.append (STR);//Add the contents of each read to the back of the variable string;
}
str.reverse ();//Drop variable string inverse value;
str=str.tostring ();//Converts a mutable string to a normal string, because write () can only output parameters of type string
Bw.write (str);
Bw.flush ();
Bw.close ();
}

}

Hope to help you with!

All rights reserved, please contact Bo Master!

Java Programming---IO stream reads the contents of the file and outputs its inverse value to the console

Related Article

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.