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

发布于 2024-07-19 08:13:13 字数 357 浏览 7 评论 0原文

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

重复:stackoverflow.com/questions/375910

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

Possible Duplicate:
Create a temporary directory in Java

Duplicate: 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剪不断理还乱 2024-07-26 08:13:13

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

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

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();
请恋爱 2024-07-26 08:13:13

您无法使用 java.io.tmpdir 属性定义的目录有什么原因吗?

IE

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

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

ie

String dirName = System.getProperty("java.io.tmpdir");
我纯我任性 2024-07-26 08:13:13

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

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

涫野音 2024-07-26 08:13:13

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文