package com.yi21.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Yi21FilesProbeContentType {
public static void main(String[] args) {
try {
Path path = Paths.get("com\\yi21\\files\\Yi21FilesProbeContentType.java");
String type = Files.probeContentType(path);
System.out.println(path + " 的类型为: " + type);
} catch (IOException e) {
System.out.println("出错: " + e.getMessage());
}
}
}
获取文件类型
最新推荐文章于 2024-10-25 17:28:15 发布
该博客展示了如何在Java中使用Files.probeContentType方法来探测指定路径文件的MIME类型。示例代码读取了'Yi21FilesProbeContentType.java'文件并打印其内容类型。

4404

被折叠的 条评论
为什么被折叠?



