To be very clear up front: I do not care what the file extension is, only the actual contents.** I am essentially trying to find a Java implementation of the file
command.
I am currently writing an image sorter that converts all my photos to PNG format. To do this, I have to convert my files if they are JPG or Web/P or anything else. I went around Stack Overflow and all the responses were looking at the file extension, which is not what I am interested in. I am trying to use Files.probeContentType()
, but (as far as I can tell) only looks at the file extension:
public class Type {
public static void main(String[] args) throws IOException {
System.out.println(Files.probeContentType(new File(args[0]).toPath()));
}
}
bleh@bleh:/tmp$ file png
png: PNG image data, 600 x 600, 8-bit/color RGB, non-interlaced
bleh@bleh:/tmp$ java Type png
null
As stated above, I do not care what the file extension is. I am simply trying to approximate the file
command in Java.
I am also open to suggestions of a different programming language entirely (though not bash).