java - MimeTypeMap fail to return extension for a filename that contains spaces -


i trying retrieve extension file using mimetypemap.class of android.webkit package.

file file = new file(someurl);  string ext = mimetypemap.getsingleton() .getfileextensionfromurl(file.getabsolutepath()); 

ext returns null or empty if file.getname() contains blank spaces!

how solve it?

you can try

    public static string getmimetype(file file) {             string extension = getextension(file.getname());             if (extension.length() > 0)                 return mimetypemap.getsingleton().getmimetypefromextension(extension.substring(1));              return "application/octet-stream";         }  public static string getextension(string uri) {         if (uri == null) {             return null;         }          int dot = uri.lastindexof(".");         if (dot >= 0) {             return uri.substring(dot);         } else {             // no extension.             return "";         }     } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -