// User didn't add the XLS extension; add it automatically
if (file.getName ().lastIndexOf (".") > 0)
{
fileName = file.getName ().toLowerCase ().replaceAll (".*$", ".xls");
System.out.println ("*** ALREADY HAS AN EXTENSION ***");
System.out.println ("Renamed to " + fileName);
}
...
What I'm trying to do is remove a file extension from a string and add my own. For example, in my application, I'm checking to see if there is a period in the file.getName() string. If there is, I want to replace anything from the period on with nothing, but I don't think my regular expression is right.
If I type in "file.txt", I get:
*** ALREADY HAS AN EXTENSION ***
Renamed to .xls.xls
Basically, my regular expression is incorrect, but I don't see what I'm missing.