有时候在测试类跑数据,数据量比较大,直接在控制台打印不是很好,则需要我们写入到外部文件。
public class demo {
@Test
public void writer() {
PrintWriter PrintWriter;
try {
PrintWriter = new PrintWriter(new FileWriter("D:\\\\WORK\\\\demo.txt"));
for(int i=0;i<100;i++){
PrintWriter.printf(i+" say hello");
PrintWriter.printf("\n");
PrintWriter.flush();
}
PrintWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
在指定路径,必须要存在如WORK的文件夹,不然会找不到路径