###############基本功能
写
FileWriter fw = new FileWriter("xxx.txt"); fw.write("哈喽"); fw.close();
读
FileReader fr = new FileReader("xxx.txt"); int ch = 0; while((ch = fr.read()) != -1){ System.out.println((char)ch); } fr.close();
###############字符流缓冲区
写入
private static void writeTextByBuffered() throws IOException { FileWriter fw = new FileWriter("char_xxx.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write("小红"); bw.newLine(); bw.write("小花,小华"); bw.flush(); bw.close(); }
读取
private static void writeTextByBuffered() throws IOException { FileWriter fw = new FileWriter("char_xxx.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write("小红"); bw.newLine(); bw.write("小花,小华"); bw.flush(); bw.close(); }
读取键盘录入信息,Scanner=流+正则表达式。方法是按照某种规则在读取数据
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in);
bufr.readLine();
原文地址:https://www.cnblogs.com/-nbloser/p/8994905.html
时间: 2024-10-03 02:14:30