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!