mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复PathUtil.getMimeType可能造成的异常
This commit is contained in:
@@ -620,8 +620,9 @@ public class PathUtil {
|
||||
public static String getMimeType(Path file) {
|
||||
try {
|
||||
return Files.probeContentType(file);
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
} catch (IOException ignore) {
|
||||
// issue#3179,使用OpenJDK可能抛出NoSuchFileException,此处返回null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -80,6 +80,12 @@ public class PathUtilTest {
|
||||
Assert.assertEquals("application/x-7z-compressed", contentType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue3179Test() {
|
||||
final String mimeType = PathUtil.getMimeType(Paths.get("xxxx.jpg"));
|
||||
Assert.assertEquals("image/jpeg", mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* issue#2893 target不存在空导致异常
|
||||
*/
|
||||
|
Reference in New Issue
Block a user