在java中打开临时文件 [英] open temp file in java

查看:138
本文介绍了在java中打开临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将字符串写入临时文件( temp.txt ),我想在我关闭该文件后点击我的awt窗口按钮时应该打开该文件文件(在打开该文件后),我该怎么做?

I'm writing string to temporary file (temp.txt) and I want that file should open after clicking button of my awt window it should delete when I close that file (after opening that file), how can I do this?

这是我用来在Java中创建临时文件的代码:

This is the code that I have been using to create temporary file in Java:

File temp = File.createTempFile("temp",".txt");

FileWriter fileoutput = new FileWriter(temp);
Bufferedwriter buffout = new BufferedWriter(fileoutput);


推荐答案

由以下人员创建的文件:

A file created by:

File temp = File.createTempFile("temp",".txt");

不会删除,请参阅 javadoc ,你必须致电

Will not be deleted, see javadoc, you have to call

temp.deleteOnExit();

所以JVM会在退出时删除文件...

so the JVM will delete the file on exit...

这篇关于在java中打开临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆