How to write a probeContentType() and Usage?

时间:2023-03-09 05:06:49
How to write a probeContentType() and Usage?

Files.probeContentType() is an instance of FileTypeDetector class's abstract method String FileTypeDetector.probeContentType(), it's an extension based detector. So extend it in a new class or even anonyinter class (cannot do that because FileTypeDetector is an abstract class) might work.

 public class MyDetector extends java.nio.file.spi.FileTypeDetector{
public String probeContentType(Path path) throws IOException{
return SOMESTRING;
}
}
 //Call the detector
String type = MyDetector.probeContentType(path);