Java中如何创建临时目录/文件夹呢?

书欣 Java经验 发布时间:2023-07-17 15:56:04 阅读数:6403 1
下文笔者讲述java中创建临时目录及文件夹的方法及示例分享,如下所示
创建临时目录
    使用JDK7中新Files.createTempDirectory类
	  即可创建临时目录
例:创建临时目录
public static File createTempDirectory()
    throws IOException
{
    final File temp;

    temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
    if(!(temp.delete()))
    {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }

    if(!(temp.mkdir()))
    {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }
    return (temp);
}
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaJingYan/202307/16895805997094.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者