如何在 java 6 中创建一个临时文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/817420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:49:08  来源:igfitidea点击:

how can I create a temporary folder in java 6?

javatemporary-directory

提问by Geo

Possible Duplicate:
Create a temporary directory in Java

可能的重复:
在 Java 中创建一个临时目录

Duplicate: stackoverflow.com/questions/375910

重复:stackoverflow.com/questions/375910

Is there a way of creating a temporary folder in java ? I know of File's static method createTempFile, but this will only give me a temporary file.

有没有办法在 java 中创建临时文件夹?我知道 File 的静态方法 createTempFile,但这只会给我一个临时文件。

采纳答案by John Meagher

I've never seen a good solution for this, but this is how I've done it.

我从来没有见过一个好的解决方案,但这就是我所做的。

File temp = File.createTempFile("folder-name","");
temp.delete();
temp.mkdir();

回答by Esko Luontola

I write my own utility classes for creating temporary directories and for disposing them when they are not anymore needed. For example like this.

我编写了自己的实用程序类来创建临时目录并在不再需要它们时处理它们。例如像这样

回答by cagcowboy

Any reason you can't use the directory defined by the java.io.tmpdir property?

有什么理由不能使用 java.io.tmpdir 属性定义的目录?

ie

IE

String dirName = System.getProperty("java.io.tmpdir");

回答by Brian Agnew

I would check out this past question in SOfor a solution. Or this one!

我会在 SO 中查看这个过去的问题以寻求解决方案。或者这个