mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
!541 新增cn.hutool.core.io.FileUtil#createTempFile重载方法
Merge pull request !541 from huzhongying3/v5-dev
This commit is contained in:
commit
9dcf13ab97
@ -891,6 +891,48 @@ public class FileUtil extends PathUtil {
|
|||||||
return createTempFile("hutool", null, dir, true);
|
return createTempFile("hutool", null, dir, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在默认临时文件目录下创建临时文件,创建后的文件名为 prefix[Randon].tmp。
|
||||||
|
* 默认临时文件目录由系统属性 <code>java.io.tmpdir<code> 指定。
|
||||||
|
* 在 UNIX 系统上,此属性的默认值通常是 <code>"tmp"<code> 或 <code>"vartmp"<code>;
|
||||||
|
* 在 Microsoft Windows 系统上,它通常是 <code>"C:\\WINNT\\TEMP"<code>。
|
||||||
|
* 调用 Java 虚拟机时,可以为该系统属性赋予不同的值,但不保证对该属性的编程更改对该方法使用的临时目录有任何影响。
|
||||||
|
* @return 临时文件
|
||||||
|
* @throws IORuntimeException IO异常
|
||||||
|
*/
|
||||||
|
public static File createTempFile() throws IORuntimeException {
|
||||||
|
return createTempFile("hutool", null, null, true);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 在默认临时文件目录下创建临时文件,创建后的文件名为 prefix[Randon].suffix。
|
||||||
|
* 默认临时文件目录由系统属性 <code>java.io.tmpdir<code> 指定。
|
||||||
|
* 在 UNIX 系统上,此属性的默认值通常是 <code>"tmp"<code> 或 <code>"vartmp"<code>;
|
||||||
|
* 在 Microsoft Windows 系统上,它通常是 <code>"C:\\WINNT\\TEMP"<code>。
|
||||||
|
* 调用 Java 虚拟机时,可以为该系统属性赋予不同的值,但不保证对该属性的编程更改对该方法使用的临时目录有任何影响。
|
||||||
|
* @param suffix 后缀,如果null则使用默认.tmp
|
||||||
|
* @param isReCreat 是否重新创建文件(删掉原来的,创建新的)
|
||||||
|
* @return 临时文件
|
||||||
|
* @throws IORuntimeException IO异常
|
||||||
|
*/
|
||||||
|
public static File createTempFile(String suffix, boolean isReCreat) throws IORuntimeException {
|
||||||
|
return createTempFile("hutool", suffix, null, isReCreat);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 在默认临时文件目录下创建临时文件,创建后的文件名为 prefix[Randon].suffix。
|
||||||
|
* 默认临时文件目录由系统属性 <code>java.io.tmpdir<code> 指定。
|
||||||
|
* 在 UNIX 系统上,此属性的默认值通常是 <code>"tmp"<code> 或 <code>"vartmp"<code>;
|
||||||
|
* 在 Microsoft Windows 系统上,它通常是 <code>"C:\\WINNT\\TEMP"<code>。
|
||||||
|
* 调用 Java 虚拟机时,可以为该系统属性赋予不同的值,但不保证对该属性的编程更改对该方法使用的临时目录有任何影响。
|
||||||
|
*
|
||||||
|
* @param prefix 前缀,至少3个字符
|
||||||
|
* @param suffix 后缀,如果null则使用默认.tmp
|
||||||
|
* @param isReCreat 是否重新创建文件(删掉原来的,创建新的)
|
||||||
|
* @return 临时文件
|
||||||
|
* @throws IORuntimeException IO异常
|
||||||
|
*/
|
||||||
|
public static File createTempFile(String prefix, String suffix, boolean isReCreat) throws IORuntimeException {
|
||||||
|
return createTempFile(prefix, suffix, null, isReCreat);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 创建临时文件<br>
|
* 创建临时文件<br>
|
||||||
* 创建后的文件名为 prefix[Randon].tmp
|
* 创建后的文件名为 prefix[Randon].tmp
|
||||||
|
@ -452,4 +452,18 @@ public class FileUtilTest {
|
|||||||
List<String> list = ListUtil.toList("a", "b", "c");
|
List<String> list = ListUtil.toList("a", "b", "c");
|
||||||
FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.CHARSET_UTF_8);
|
FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.CHARSET_UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void createTempFileTest(){
|
||||||
|
File nullDirTempFile = FileUtil.createTempFile();
|
||||||
|
Assert.assertTrue(nullDirTempFile.exists());
|
||||||
|
|
||||||
|
File suffixDirTempFile = FileUtil.createTempFile(".xlsx",true);
|
||||||
|
Assert.assertTrue(FileUtil.getSuffix(suffixDirTempFile).equals("xlsx"));
|
||||||
|
|
||||||
|
File prefixDirTempFile = FileUtil.createTempFile("prefix",".xlsx",true);
|
||||||
|
Assert.assertTrue(FileUtil.getPrefix(prefixDirTempFile).startsWith("prefix"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user