I'm basically trying to split a string on the last period to capture the file extension. But sometimes the file doesn't have any extension, so I'm anticipating that.
But the problem is that some file names have periods before the end like so...
/mnt/sdcard/OG Ron C, Chopstars & Drake - Choppin Ain't The Same-2013-MIXFIEND/02 Drake - Connect (Feat. Fat Pat) (Chopped Not Slopped).mp3
So when that string comes up it chops it at "02 Drake - Connect (Feat."
This is what I've been using...
String filePath = intent.getStringExtra(ARG_FILE_PATH);
String fileType = filePath.substring(filePath.length() - 4);
String FileExt = null;
try {
StringTokenizer tokens = new StringTokenizer(filePath, ".");
String first = tokens.nextToken();
FileExt = tokens.nextToken();
}
catch(NoSuchElementException e) {
customToast("the scene you chose, has no extension :(");
}
System.out.println("EXT " + FileExt);
File fileToUpload = new File(filePath);
How do I split the string at the file extension but also be able to handle and alert when the file has no extension.