您的位置:首页 > 编程语言 > Java开发

java小知识-将System.out.println到控制台的内容打印并保存在新的文件中(例如txt文件从)

2018-01-30 16:23 513 查看
import java.io.FileOutputStream;
import java.io.PrintWriter; 
import java.io.PrintStream; 
import java.io.FileNotFoundException;
String strJSON = "这是一段字符串,这段字符串将会打印到指定文件中。";
//日志输出到指定文件中
PrintStream out;
try {
out = new PrintStream("C://Users//whr-pc//Desktop//classpath//img//Systemout.txt");

System.setOut(out);
System.out.println(strJSON);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java