50,547
社区成员
发帖
与我相关
我的任务
分享
// 指定输出文件
PrintStream ps = new PrintStream(new File("d:\\out.txt"));
// 将指定的输出赋给系统输出
System.setOut(ps);
int i = 0;
while (i < 100) {
System.out.println(i + " " + UUID.randomUUID().toString());
i++;
}
System.out.flush();
System.out.close();
可以通过println,也可以通过 "\r\n" 来换行
while (i < 100) {
System.out.print(i + " " + UUID.randomUUID().toString() + "\r\n");
i++;
}
// 指定输出文件
PrintStream ps = new PrintStream(new File("d:\\out.txt"));
// 将指定的输出赋给系统输出
System.setOut(ps);
System.out.println("123");
System.out.println("345");
System.out.flush();
System.out.close();
代码仅供参考