Split string on the last occurrence of some character
You can try this
int i = s.lastIndexOf(c);
String[] a = {s.substring(0, i), s.substring(i)};
Is this Java? If so, why don't you use "java.io.File.getName".
For example:
File f = new File("/aaa/bbb/ccc.txt");
System.out.println(f.getName());
Out:
ccc.txt
It might be easier to just assume that files which end with a dot followed by alphanumeric characters have extensions.
int p=filePath.lastIndexOf(".");
String e=filePath.substring(p+1);
if( p==-1 || !e.matches("\\w+") ){/* file has no extension */}
else{ /* file has extension e */ }
See the Java docs for regular expression patterns. Remember to escape the backslash because the pattern string needs the backslash.