JAVA判断文件的内容类型
2017-02-12 21:11
330 查看
Java 7 新的特性,判断文件的内容类型。
Program to demonstrate Java 7 new feature : Determining the file content type. package com.hubberspot.nio; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class FileContentType { public static void main(String[] args) { printContentType("D:/Downloads/java.txt"); printContentType("D:/Downloads/java.ppt"); printContentType("D:/Downloads/java.doc"); printContentType("D:/Downloads/java.jar"); } private static void printContentType(String pathToFile) { Path path = Paths.get(pathToFile); String contentType = null; try { contentType = Files.probeContentType(path); } catch (IOException e) { e.printStackTrace(); } System.out.println("File content type is : " + contentType); } }
相关文章推荐
- java通过文件头内容判断文件类型
- java通过文件头内容判断文件类型
- java通过文件头内容判断文件类型
- Java如何获取文件的内容类型?例如:image/gif
- 根据文件内容前几个字节,判断文件类型
- java上传文件以流方式判断类型
- java上传文件以流方式判断类型
- java如何判断一个文件的类型
- Java根据文件头判断文件类型
- Java判断文件的编码类型。
- Java学习-008-判断文件类型实例
- Java判断文件类型
- java判断两个文件的内容是否完全一样
- 160414、java上传文件以流方式判断类型
- java如何判断一个文件的类型
- 判断文件类型是否为图片的方法——Java实现
- 在Java中判断一个文件是否是图片和其类型的方法
- java 根据头文件码判断文件类型
- Java根据文件内容判断是否是图片
- java_js判断上传的文件类型.