java逐行读取和写入文本文件txt
为了提高字符复制的效率。可以使用逐行读写的功能,这个例子给出
逐行写入文本
public class TestFileWriter {
public static void main(String[] args) {
FileWriter fw = null;
try {
fw = new FileWriter("d://test.txt",true);
String c = "abs"+"\r\n";
fw.write(c);
fw.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("写入失败");
System.exit(-1);
}
}
}
逐行读取文本
public static final void readF1(String filePath) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(filePath)));
for (String line = br.readLine(); line != null; line = br.readLine()) {
System.out.println(line);
}
br.close();
}
posted on 2016-01-14 10:37 1130136248 阅读(629) 评论(0) 编辑 收藏 举报