mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
59cad19989
commit
620f660bdf
@ -539,4 +539,19 @@ public class PathUtil {
|
|||||||
Assert.notNull(path);
|
Assert.notNull(path);
|
||||||
return path.toAbsolutePath().normalize();
|
return path.toAbsolutePath().normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得文件的MimeType
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return MimeType
|
||||||
|
* @since 5.5.5
|
||||||
|
*/
|
||||||
|
public static String getMimeType(Path file) {
|
||||||
|
try {
|
||||||
|
return Files.probeContentType(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IORuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.hutool.core.io.file;
|
package cn.hutool.core.io.file;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -33,4 +34,10 @@ public class PathUtilTest {
|
|||||||
public void moveTest(){
|
public void moveTest(){
|
||||||
PathUtil.move(Paths.get("d:/lombok.jar"), Paths.get("d:/test/"), false);
|
PathUtil.move(Paths.get("d:/lombok.jar"), Paths.get("d:/test/"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMimeTypeTest(){
|
||||||
|
final String mimeType = PathUtil.getMimeType(Paths.get("d:/test/test.jpg"));
|
||||||
|
Assert.assertEquals("image/jpeg", mimeType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user