plain text file write out

Character stream: plain text. .txt.html
node stream: Reader FileReader
Writer FilterWriter
plain text read
1. Establish contact
2. Select stream: Reader FileReader
3. Read: char[] cr=new char[1024];
4. Close the stream.
Write out plain text
1. Establish connection
2. Select stream: Writer FilterWriter
3. Read: char[] cr=new char[1024];
4. Close the stream.
package javaio;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
*
* Plain text read
1. Establish connection
2. Select stream: Reader FileReader
3. Read: char[] cr=new char[1024];
4. Close the stream.
* @author Lenovo
*
*/
public class Text2 {

public static void main(String[] args) throws FileNotFoundException {
    //建立联系
    File file=new File("G:\\filetext\\add");
    //选择流
    Reader reader=new FileReader(file);
    char[] ch=new char[1024];
    int len=0;
    try {
        while((len=reader.read(ch))!=-1) {
            String string=new String(ch, 0, len);
            System.out.println(string);
        }
    } catch (IOException e) {
        System.out.println("读取失败");
        e.printStackTrace();
    }
}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325860420&siteId=291194637