###21.01_IO flow ( Character stream FileReader)
* 1. What is a character stream
    *  Character stream can read and write characters directly IO flow
    *  Character stream reads characters , We need to read the byte data first , Then change to character . If you want to write characters , You need to convert characters to bytes and write .    
* 2.FileReader
    * FileReader Class read() Method can be read by character size

        FileReader fr = new FileReader("aaa.txt");                // Create an input stream object , relation aaa.txt
        int ch;
        while((ch = fr.read()) != -1) {                            // Assign the read character to ch
            System.out.println((char)ch);                        // Force the read character to print
        }
        
        fr.close();                                                // Shut off flow

###21.02_IO flow ( Character stream FileWriter)
* FileWriter Class write() Method can automatically convert characters into bytes and write

FileWriter fw = new FileWriter("aaa.txt");
        fw.write("aaa");
        fw.close();

###21.03_IO flow ( Copy of character stream )
    FileReader fr = new FileReader("a.txt");
    FileWriter fw = new FileWriter("b.txt");
    
    int ch;
    while((ch = fr.read()) != -1) {
        fw.write(ch);
    }
    
    fr.close();
    fw.close();

###21.04_IO flow ( When to use character stream )
*  Character streams can also copy text files , But not recommended . Because when reading, bytes will be converted to characters , When you write out, you also need to return the characters to bytes .
*  The program needs to read a piece of text , Or you can use character stream when you need to write a piece of text
*  Read according to the size of the characters , Half Chinese will not appear
*  When writing, you can write the string directly , No need to convert to byte array

###21.05_IO flow ( Can character streams copy files that are not plain text )
*  You can't copy files that are not plain text
*  Because bytes are converted to characters when reading , In the process of transformation , The corresponding character may not be found , Will use ? Instead of , When writing out, the characters will be converted into bytes and written out
*  If it is ?, Write directly , In this way, the documents after writing are disordered , I can't see it

###21.06_IO flow ( Copy of custom character array )
*    
        
        FileReader fr = new FileReader("aaa.txt");            // Create character input stream , relation aaa.txt
        FileWriter fw = new FileWriter("bbb.txt");            // Create character output stream , relation bbb.txt
        
        int len;
        char[] arr = new char[1024*8];                        // Create a character array
        while((len = fr.read(arr)) != -1) {                    // Read data into a character array
            fw.write(arr, 0, len);                            // Write data from a character array to a file
        }
        
        fr.close();                                            // Turn off and release resources
        fw.close();

###21.07_IO flow ( Buffered character stream ) 
* BufferedReader Of read() Method will read several characters to the buffer at a time , And then one by one back to the program , Reduce the number of file reads , Increase of efficiency
* BufferedWriter Of write() Method writes characters to the buffer first , Write to file when buffer is full , Reduce the number of times you write files , Increase of efficiency

        BufferedReader br = new BufferedReader(new FileReader("aaa.txt"));    // Create character input stream object , relation aaa.txt
        BufferedWriter bw = new BufferedWriter(new FileWriter("bbb.txt"));    // Create character output stream object , relation bbb.txt
        
        int ch;                
        while((ch = br.read()) != -1) {        //read once , Will first read the buffer full , One by one from the buffer back to the temporary variable ch
            bw.write(ch);                    //write once , It's loading data into a character array , Fill it up and then write it out
        }
        
        br.close();                            // Shut off flow
        bw.close();

###21.08_IO flow (readLine() and newLine() Method )    
* BufferedReader Of readLine() Method can read a line of characters ( Does not contain line breaks )
* BufferedWriter Of newLine() You can output a cross platform line feed "\r\n"

        BufferedReader br = new BufferedReader(new FileReader("aaa.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("bbb.txt"));
        String line;
        while((line = br.readLine()) != null) {
            bw.write(line);
            //bw.write("\r\n");                    // Only support windows System
            bw.newLine();                        // Cross platform
        }
        
        br.close();
        bw.close();

###21.10_IO flow (LineNumberReader) 
* LineNumberReader yes BufferedReader Subclasses of , It has the same function , And you can count the line numbers
    *  call getLineNumber() Method to get the current line number
    *  call setLineNumber() Method to set the current line number

        LineNumberReader lnr = new LineNumberReader(new FileReader("aaa.txt"));
        String line;
        lnr.setLineNumber(100);                                    // set nu
        while((line = lnr.readLine()) != null) {
            System.out.println(lnr.getLineNumber() + ":" + line);// Get line number
        }
        
        lnr.close();

###21.11_IO flow ( Decoration design mode )


        interface Coder {
            public void code();
        }
        
        class Student implements Coder {
        
            @Override
            public void code() {
                System.out.println("javase");
                System.out.println("javaweb");
            }
            
        }
        
        class HeiMaStudent implements Coder {
            private Student s;                        // Get a reference to the wrapped class
            public HeiMaStudent(Student s) {        // When you create an object through a constructor , Incoming wrapped objects
                this.s = s;
            }
            @Override
            public void code() {                    // Upgrade its original functions
                s.code();
                System.out.println(" database ");
                System.out.println("ssh");
                System.out.println(" Android ");
                System.out.println(".....");
            }
            
        }

###21.12_IO flow ( Use the specified code table to read and write characters ) 
* FileReader Use the default code table to read files , If you need to use the specified code table to read , Then you can use InputStreamReader( Byte stream , Encoding table )
* FileWriter Is to write out the file using the default code table , If you need to use the specified code table to write , Then you can use OutputStreamWriter( Byte stream , Encoding table )

        BufferedReader br =                                     // Efficient reading with specified code table
                new BufferedReader(new InputStreamReader(new FileInputStream("UTF-8.txt"), "UTF-8"));
        BufferedWriter bw =                                     // Write efficiently with the specified code table
                new BufferedWriter(new OutputStreamWriter(new FileOutputStream("GBK.txt"), "GBK"));
        int ch;
        while((ch = br.read()) != -1) {
            bw.write(ch);
        }
        
        br.close();
        bw.close();

###21.18_IO flow ( summary )
* 1. Will use BufferedReader Read GBK Code table and UTF-8 The characters of the code table
* 2. Will use BufferedWriter Write characters to GBK Code table and UTF-8 Code table file
* 3. Will use BufferedReader Read a line from the keyboard

java-IO flow - Character stream -FileReader、FileWriter、 Copy of custom small array 、BufferedReader、BufferedWriter、readLine() and newLine() Method 、LineNumberReader、 Read and write characters using the specified code table

  1. java IO operation :FileInputStream,FileOutputStream,FileReader,FileWriter example

    FileInputStream <span style="font-family:Verdana;">import java.io.File; import java. ...

  2. FileReader、 FileWriter、readLine() and newLine()、LineNumberReader( The 21st )

    1. Character stream FileReader * 1. What is a character stream * Character stream can read and write characters directly IO flow * Character stream reads characters , We need to read the byte data first , Then change to character . If you want to write characters , You need to convert characters to bytes and write . ...

  3. Java IO File and stream Foundation

    Java IO File and stream Foundation @author ixenos Abstract : create a file . File filtering . Stream classification . Flow structure . Common streams . File stream . Byte array stream ( buffer ) How to create a file # When we call File Class , Just in ...

  4. Java IO The processing flow of

    One . Processing flow : Enhancements , Provide performance , On top of the node flow . Two . The relationship between node flow and processing flow Node flow ( Byte stream . Character stream ) be in IO The first line of operation , All operations have to be done through them : Processing streams can process other streams ( Improve efficiency or operational flexibility ) ...

  5. Java IO( seventeen )FIleReader and FileWriter

    Java IO( seventeen )FIleReader and FileWriter One . Introduce FIleReader and FileWriter Is a convenient class for reading and writing character files , Respectively inherited from  InputStreamReader ...

  6. Java API —— code &amp; IO flow ( InputStreamReader &amp; OutputStreamWriter &amp; FileReader &amp; FileWriter &amp; BufferedReader &amp; BufferedWriter )

    1. code     1) An overview of the coding table          A table of characters and their corresponding values     2) Common code table         · ASCII/Unicode Character set :ASCII It's the American standard information interchange code , Use one ...

  7. 10.3 io flow Positive FileReader FileWriter Read and write code

    One .FileWriter Section : 1)FileWriter fw = new FileWriter("a.txt",true);// Indicates append write , The default is false. Normal condition : More execution ...

  8. java io series 22 And FileReader and FileWriter

    FileReader Is the class used to read the character stream , It is inherited from InputStreamReader. To read the original byte stream , Please consider using FileInputStream.FileWriter Is the class used to write to the character stream , It inherited ...

  9. Java IO The role of transfer converter

    stay <Java Network programming > in , There is such a saying : ”Reader and Writer The most important subclass is InputStreamReader and OutputStreamWriter class . InputStreamRe ...

Random recommendation

  1. php Serialization and deserialization

    One Use system functions serialize and unserilazie <?php class A { public $a = "aa"; public $b = 10; functio ...

  2. CAGradientLayer Some attribute parsing of

    CAGradientLayer Some attribute parsing of iOS in Layer Coordinate system of : effect : - (void)viewDidLoad { [super viewDidLoad]; CAGradientLaye ...

  3. Web Service working principle

    Web Service Basic concepts Web Service Also called XML Web Service WebService It's one that can receive from Internet perhaps Intranet Requests passed from other systems on , Lightweight ...

  4. Technology is not good, how to get to the domestic IT Giant Offer( turn )

    not long ago ,byvoid The screenshot of the interview result of alixing plan is leaked , Cause countless IT Loser's admiration and admiration . Look at these bulls ,NOI gold medal , Open source community celebrities , I started writing in grade three Basic... While kneeling down, we can't help thinking , Compared with these bulls , As the vast majority of Technology ...

  5. ubuntu eclipse establish server Tips coud not load the tomcat server configuration at /opt/apache ... Solutions for

    ubuntu eclipse establish server Tips coud not load the tomcat server configuration at /opt/apache ... Solutions for & ...

  6. Android Exemption Root Realization Apk Silent installation , Covering the mainstream of the compatible market 98% Model of

    Address :http://blog.csdn.net/sk719887916/article/details/46746991 author : skay Recently doing apk Self silent update , In the case of getting built-in , Or already root ...

  7. front end /C# Front and back interactive file upload 、 download

    Tried many ways , Finally confirm this comprehensive and simple version . I don't say much nonsense , Sticker code . Upload files input Of type Name it file, The file can be uploaded . Um. ~~~ Now? html It's still very powerful .Good! front end Single file upload Html: ...

  8. postgresql9.1 Database encryption and decryption

    -- The following for postgresql9.1 Database encryption and decryption module configuration -- Set up schemapsql -U postgres -h localhostset schema 'sbdc';-- Generate logs \o E:/sh ...

  9. Django Inquire about SQL sentence

    Django Inquire about SQL sentence # 1 res=models.Book.objects.all() # print(res)#<QuerySet [<Book: Book object> ...

  10. 10 Base and 16 Conversion between bases delphi

    delphi There is a direct way to 10 Base to zero 16 Function of base : function   IntToHex(Value:   Integer;   Digits:   Integer):   string;   o ...