首页 > 代码库 > read输入流与writer输出流的对比
read输入流与writer输出流的对比
package io.day4;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;
public class Test {
public static void main(String[] args) throws Exception {
read();//输入流
write();//输出流
}
//输出流
private static void write() throws Exception {
Writer wt = new FileWriter("Test/xy.txt");
char[] c = {‘谁‘,‘是‘,‘大‘,‘傻‘,‘逼‘};
wt.write(c);
wt.close();
}
//输入流
private static void read() throws Exception {
Reader rd= new FileReader("Test/xy.txt");
int b=rd.read(); //读取单行字符
System.out.println((char)b);
char[] chars = new char[10]; //读取10个字符
int length = rd.read(chars);
System.out.println(Arrays.toString(chars));
rd.close();
}
}
read输入流与writer输出流的对比