写字符文件操作
public class FileWriteDemo {
public static void main(String[] args) throws IOException {
FileWriter fw = new FileWriter("d:\\a.txt");
fw.write("I love you 我爱你");
fw.flush();
fw.close();
}
}
读字符文件
读数据--输出流--FileReader
FileReader的构造方法
FileReader(String fileName)
输入流读入数据步骤
A:创建输入流对象
B:调用输入流对象的读数据方法
C:释放资源
读字符文件
public class FileReaderDemo {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("test.txt");
int ch;
while((ch = fr.read())!=-1) {
System.out.print((char)ch);
}
fr.close();
}
}