PrintWriter close()

来源:互联网 发布:mac os x常用软件 编辑:程序博客网 时间:2024/04/29 00:06

File file=new File("a.txt");                            //1

PrintWriter writer=new PrintWriter(file);   //2

String text="?";

writer.write(text);     //3

//

writer.close()     //4



如果a.txt不存在,程序运行到2时,才创建文件。

运行到3时,不会立即把内容写入a.txt


运行完4

writer.close()  才会写入内容。close() 很重要一定要正确关闭

0 0