今天做了一个测试:
@Testpublic void fileOut() throws Exception {FileOutputStream out = new FileOutputStream(new File("test.txt"), false);out.write("1".getBytes());out.write("2".getBytes());File file = new File("test.txt");file.delete();file.createNewFile();out.flush();
// FileOutputStream out1 = new FileOutputStream(new File("test.txt"), false);out.write("3".getBytes());
// out.write("2".getBytes());
// out1.write("4".getBytes());out.close();String s = util.MyFileTool.readFile(new File("test.txt"));System.out.println(s);}
最后结果仍然为123,说明out文件流已经保存在程序运行时的内存当中,其实在写入前把文件删除掉,但原来的文件流对象依然没有发生改变,切记!