This is not one of those questions for which I dont know a answer but I am trying to find a better more effective way so here I go.
when saving file name in java I am saving it like this
private static final String REPORT_FILE_PREFIX = "ask_ques"; //$NON-NLS-1$
private static final String TXT_EXTENSION = ".txt"; //$NON-NLS-1$
StringBuilder fileName= new StringBuilder();
fileName.append(tempFilePath.toString()).append(REPORT_FILE_PREFIX)
.append(uniqueId.toString()).append(TXT_EXTENSION);
This is going to save the file something like ask_ques_1234.txt
all is well and good. Now when opening the file I need to open in based on its extension like notepad for txt, excel so on and so forth.Like I do below
if (FilenameUtils.getExtension(fileName.getName()) == CSV_EXTENSION) {
// Open the .csv file based on the local file type
// association
} else if (FilenameUtils.getExtension(fileName.getName()) == TXT_EXTENSION) {
// open the .txt file based on file type assocaition
}
the problem here is that FilenameUtils.getExtension(reportFile.getName())
returns a value of txt but TXT_EXTENSION has .txt
as its value.
Do not want to create static variable for the .
. Wanted to see if there is simeple regex or something similar you guys know off to ignore the .
when comparing.