how to find file type in java -


how find file type, example if .xls go xlsconvertcsv method or .xlsx go xlsscsv method, how that.?

i used getcanonicalpath() method,i found file type, did not able convert string file.

public static void main(string[] args) throws ioexception {          file inputfile = new file("test.xls");          file outputfile = new file("output1.csv");          string out=inputfile .getcanonicalpath();          if(out.endswith(".xls"))         {           system.out.print("text filei\n"+out);           converttoxls(out, outputfile);         }     //system.out.println("out"+out);     //converttoxls(inputfile, outputfile); } 

you can use following code that

import javax.activation.mimetypesfiletypemap; import java.io.file;  class getmimetype {    public static void main(string args[]) {       file f = new file("gumby.gif");       system.out.println("mime type of " + f.getname() + " " +                      new mimetypesfiletypemap().getcontenttype(f)); // expected output : // "mime type of gumby.gif image/gif" 

} }


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -