如何在 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
how can I create a temporary folder in java 6?
提问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
回答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!