Reader、Writer是所有字符流的超类。
Writer类方法
void write(String str)
void write(char[] cbuf, int off, int len);
void flush()
void close
OutputStreamWriter构造方法字符编码默认为系统编码,可以不写
FileWriter的append默认为false,可以不写。另一个构造(File file, boolean append)
Writer out = new FileWriter("E:/a.txt", true); OutputStream ops = new FileOutputStream("E:/a.txt", true); Writer out = new OutputStreamWriter(ops, "GBK"); // 默认系统编码,可以不写
Reader类
int read(char[] cbuf)
InputStreamReader与OutputStreamWriter类似
FileReader 与 FileWriter类似’
Reader in = new FileReader("E:/gbk.txt"); InputStream inStream = new FileInputStream("E/gbk.txt"); Reader in = new InputStreamReader(inStream, "gbk");
时间: 2024-10-19 21:50:40