逐行读取本地read.text文件,再写入到write.text文件中
package cn.test;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
public class readWrite_demo {
public static void main(String[] args) throws Exception {
StringBuilder result = new StringBuilder();
String file = "d:\\read.txt";
String fileOut = "d:\\write.txt";
PrintStream ps = new PrintStream(new FileOutputStream(fileOut));
BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
String textLine = null;
while((textLine = br.readLine())!=null){//使用readLine方法,一次读一行
System.out.println(textLine);
ps.append(textLine+"\r\n");// 在已有的test.txt基础上append添加字符串+换行
}
br.close();
ps.close();
}