参考手册:
BufferedReader
BufferedWriter:
关键字:
close()
newLine()
写一行行分隔符。
write()
写一个字符
实例:
import java.io.*; public class Zfsrsc { //字符输入输出。 public static void main(String[] args) throws Exception { lx1(); } private static void lx2() throws Exception { //BufferedWriter 写。 BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\ja.txt" )); bw.write("您好啊召唤师。"); bw.newLine(); bw.write("欢迎来到德莱联盟"); bw.write("德玛西亚永不言弃"); bw.write("战火,已经蔓延到了我的国家。"); bw.close(); } private static void lx1() throws Exception { //创建字符输入缓冲流对象 // // 利用BufferedReader/BufferedWriter逐行读写文件内容,提升I/O性能 BufferedReader br = new BufferedReader(new FileReader("D:\\ja.txt")); String len = null; while ((len = br.readLine())!=null){ System.out.println(len); } br.close(); } }
打印结果:
lx1:
lx2: