黑马程序员技术交流社区
标题:
重定位Out至文件,输出后文件为空,求解!
[打印本页]
作者:
真实姓名被注册
时间:
2015-7-20 13:37
标题:
重定位Out至文件,输出后文件为空,求解!
import java.util.*;
import java.io.*;
public class Temp{
public static void main(String[] args){
File file=new File("hehe.txt");
try {
System.setOut(new PrintStream(
new BufferedOutputStream(
new FileOutputStream("hehe.txt"))));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("abc");
}
}
复制代码
请教,为什么程序运行后,文件"hehe.txt"中没有任何内容?
作者:
真实姓名被注册
时间:
2015-7-20 13:42
明白了,需要加句System.out.flush();
作者:
耀阳圣尊
时间:
2015-7-20 13:56
PrintStream ps= null;
File file = new File("d:\\hehe.txt");
ps = new PrintStream(new FileOutputStream(new File(
"d:\\hehe.txt"), true));
System.setOut(ps);
System.out.println("lalalal hei ma cheng xu yuan ");
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2