Monday, October 12, 2015

Check Mime type

You designate a path of a file to detect Mime type.
When you designate the file path, write this way:
C:\\Users\\John\\Pictures\\blog\\1alignment_panel.gif


import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class TestMime { public static void main(String[] args) throws IOException { BufferedReader buffreader1 = new BufferedReader(new InputStreamReader(System.in)); String mpath = ""; mpath = buffreader1.readLine(); File file = new File(mpath); Path source = Paths.get(file.getPath()); System.out.println(Files.probeContentType(source)); } }