mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
修复PathUtil.getMimeType可能造成的异常
This commit is contained in:
parent
e8adf37407
commit
824bf11d05
@ -594,8 +594,9 @@ public class PathUtil {
|
|||||||
public static String getMimeType(final Path file) {
|
public static String getMimeType(final Path file) {
|
||||||
try {
|
try {
|
||||||
return Files.probeContentType(file);
|
return Files.probeContentType(file);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException ignore) {
|
||||||
throw new IORuntimeException(e);
|
// issue#3179,使用OpenJDK可能抛出NoSuchFileException,此处返回null
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,4 +93,10 @@ public class PathUtilTest {
|
|||||||
public void moveTest2(){
|
public void moveTest2(){
|
||||||
PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false);
|
PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issue3179Test() {
|
||||||
|
final String mimeType = PathUtil.getMimeType(Paths.get("xxxx.jpg"));
|
||||||
|
Assertions.assertEquals("image/jpeg", mimeType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user