Java中如何创建临时目录/文件夹呢?
下文笔者讲述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); }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。