pom.xml引入
<dependency>
<groupId>io.github.kylin-hunter</groupId>
<artifactId>k-file-detector</artifactId>
<version>1.0.11</version>
</dependency>
实现代码
static void sss() throws IOException {
byte[] content = FileUtils.readFileToByteArray(new File(".mp4"));
// if know the file name, you can invoke: FileDetector.detect(content,"xxx.xxx)
DetectResult detectResult = FileDetector.detect(content);
List<FileType> possibleFileTypes = detectResult.getPossibleFileTypes();
for (FileType fileType : possibleFileTypes) {
System.out.println("id=" + fileType.getId()); // file type id
System.out.println("extensions=" + fileType.getExtensions()); // the extensions, may be empty
System.out.println("desc=" + fileType.getDesc()); // the description
}
}
static void kkk(){
DetectResult detectResult = FileDetector.detect(new File(".mp4")); //by file
List<FileType> possibleFileTypes = detectResult.getPossibleFileTypes();
for (FileType fileType : possibleFileTypes) {
System.out.println("id=" + fileType.getId()); // file type id
System.out.println("extensions=" + fileType.getExtensions()); // the extensions, may be empty
System.out.println("desc=" + fileType.getDesc()); // the description
}
}