> String name = yourFile.getName().substring(0, yourFile.getName().lastIndexOf('.'));
You have to check if the name contains a dot first.
This piece of code is taken from here:
http://mindprod.com/jgloss/file.html
// getting the extension of a filename, (plain or including dirname)
// This code is much faster than any regex technique.
// filename without the extension
String choppedFilename;
// extension without the dot
String ext;
// where the last dot is. There may be more than one.
int dotPlace = filename.lastIndexOf ( '.' );
if ( dotPlace >= 0 )
{
// possibly empty
choppedFilename = filename.substring( 0, dotPlace );
// possibly empty
ext = filename.substring( dotPlace + 1 );
}
else
{
// was no extension
choppedFilename = filename;
ext = "";
}