无法创建临时文件
我正在使用这段代码创建一个临时文件:
String tmpDirectoryOp = System.getProperty("java.io.tmpdir");
File tmpDirectory = new File(tmpDirectoryOp);
File fstream = File.createTempFile("tmpDirectory",".flv", tmpDirectory);
FileOutputStream fos = new FileOutputStream(fstream);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeChars("Write something");
fstream.deleteOnExit();
fos.close();
dos.close();
但是我的项目文件夹中没有 tmpDirectory.flv 。 write语句是一个循环,需要相当长的时间才能完成,所以问题不在于文件在我看到它之前就被删除了。
有什么想法吗?提前致谢
I am using this piece of code to create a temporary file:
String tmpDirectoryOp = System.getProperty("java.io.tmpdir");
File tmpDirectory = new File(tmpDirectoryOp);
File fstream = File.createTempFile("tmpDirectory",".flv", tmpDirectory);
FileOutputStream fos = new FileOutputStream(fstream);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeChars("Write something");
fstream.deleteOnExit();
fos.close();
dos.close();
But there is no tmpDirectory.flv
in my project folder. The write sentence is in a loop, which takes quite long time to finish, so the problem is not that the file is deleted before I could see it.
Any idea? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
获取操作系统的临时目录
您可以使用您已执行的
deleteOnExit()
You can get temp dir for your operating system using
You have executed
deleteOnExit()
!!请关闭直播!!
**
**
!! Please close the streams !!
**
**
您查看过
/tmp
文件夹吗?如果要在指定文件夹中创建临时文件,则需要 3 参数
createTempFile
函数Have you looked in your
/tmp
folder?If you want to create a temporary file in a specified folder, you need the 3 param
createTempFile
function尝试刷新并关闭流。
Try to flush and close the stream.