如果我传递 .mp4 扩展名或完整文件名,Java 中是否有任何 API 可以将 mime-type 或 content-Type 返回为 video/mp4?
谢谢
最佳答案
您可以使用java.nio.file.Files#ProbeFileContent(path)默认情况下,它将使用扩展检测器,除非您没有注册任何其他 java.nio.file.spi.FileTypeDetector :s
public class Main {
public static void main(String[] argv) throws Throwable {
Path path = Paths.get("c:/test.mp4");
String contentType = Files.probeContentType(path);
System.out.println(contentType);
}
}
将输出:
video/mp4
关于java - 我想在java中传递文件名xxx.mp4后接收vide/mp4 mime类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14263272/