J
jimgardener
hi
i want to extract the extension of a file as a String.Suppose the
pathname of file is F:\mycode\myimage\newimg.jpg
i need to get the extension 'jpg' only
I did it like this,
public static void main(String [] args){
String imagetomatch=args[0];
String[] words=imagetomatch.split(java.io.File.pathSeparator);
String ext=(words[words.length-1].split("\\.")[1]);
System.out.println("ext="+ext);
}
is there a better/compact way to do this?
Also ,why does'nt the .split(".") work in the above case.Why do i have
to use .split("\\.")?
thanks
jim
i want to extract the extension of a file as a String.Suppose the
pathname of file is F:\mycode\myimage\newimg.jpg
i need to get the extension 'jpg' only
I did it like this,
public static void main(String [] args){
String imagetomatch=args[0];
String[] words=imagetomatch.split(java.io.File.pathSeparator);
String ext=(words[words.length-1].split("\\.")[1]);
System.out.println("ext="+ext);
}
is there a better/compact way to do this?
Also ,why does'nt the .split(".") work in the above case.Why do i have
to use .split("\\.")?
thanks
jim