Read the conversion stream-read keyboard input keyboard input a row of data and print its capitalization, found to read a row of data principle.
That is the ReadLine method.
Can you directly use the ReadLine method to complete the reading of the keyboard input line of data?
The ReadLine method is a method in the character stream BufferedReader class.
The Read method of keyboard input is the method of byte stream inputstream.
Is it possible to convert byte streams into character stream and then use the ReadLine method of the character stream buffer?
Public classTransstreamdemo { Public Static voidMain (string[] args) {//Get Keyboard Entry ObjectsInputStream is =system.in;//Converts a byte stream object to a character stream object, using the transform stream InputStreamReaderInputStreamReader ISR =NewInputStreamReader (IS);//in order to increase efficiency, the string is fed into the buffer, using the BufferedReaderBufferedReader br =NewBufferedReader (ISR); String Line=NULL; Try { while(Line =br.readline ())! =NULL) { if("Over". Equals (line)) Break; System.out.println (Line.touppercase ()); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}View Code
Write conversion stream-converts character flow to byte stream
Public classTransStreamDemo2 { Public Static voidMain (string[] args) {//InputStream is=system.in;//InputStreamReader isr=new InputStreamReader (IS);//BufferedReader br=new BufferedReader (ISR);//can be simplified to//This is the most commonly read keyboard inputBufferedReader br =NewBufferedReader (NewInputStreamReader (system.in));//outputstream os =system.out;//OutputStreamWriter OSW = new OutputStreamWriter (OS);//bufferedwriter bw = new BufferedWriter (OSW);//can be simplified toBufferedWriter BW =NewBufferedWriter (NewOutputStreamWriter (System.out)); String Line=NULL; Try { while(line = Br.readline ())! =NULL) { if("Over". Equals (line)) Break;//Print UppercaseBw.write (Line.touppercase ()); Bw.newline (); Bw.flush (); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}View Code
Flow Operation Law----keyboard input data stored in a file
Public classTransStreamDemo3 { Public Static voidMain (string[] args)throwsIOException {bufferedreader br=NewBufferedReader (NewInputStreamReader (system.in)); BufferedWriter BW=NewBufferedWriter (NewOutputStreamWriter (NewFileOutputStream ("E:/out.txt"), "Utf-8")); String Line=NULL; while(line = Br.readline ())! =NULL) { if("Over". Equals (line)) Break; Bw.write (line); System.out.println ("Write succeeded"); Bw.newline (); Bw.flush (); } }}View Code
Prints the data for a file on the console.
Public classTransStreamDemo4 { Public Static voidMain (string[] args)throwsIOException {bufferedreader br=NewBufferedReader (NewInputStreamReader (NewFileInputStream ("E:/out.txt"), "Utf-8")); BufferedWriter BW=NewBufferedWriter (NewOutputStreamWriter (System.out)); String Line=NULL; while(line = Br.readline ())! =NULL) {bw.write (line); Bw.newline (); Bw.flush (); } }}View Code
Operation of Io stream in Java