那如果我不想把他输出到控制台,想把他输出到一个文件里面去怎么做呢?
看下面代码你就明白了。
看下面代码你就明白了。
- public static void main(String[] args) throws Exception {
- String str = "abcd";
- PrintStream out = new PrintStream("f:/test.txt");
- System.setOut(out);
- System.out.println(str);
- }
public static void main(String[] args) throws Exception { String str = "abcd"; PrintStream out = new PrintStream("f:/test.txt"); System.setOut(out); System.out.println(str); }