I am very confused by this comparison with FilenameUtils.getExtension.
I have a file chooser fc that I want to ensure that the extension is .csv.
JFileChooser fc = new JFileChooser();
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION &&
fc.getSelectedFile().isFile() &&
FilenameUtils.getExtension(fc.getSelectedFile().getName()) == "csv") {
// Do stuff
}
After some debugging, I found that the last statement was responsible for not having the if statement executed.
FilenameUtils.getExtension(fc.getSelectedFile().getName()) == "csv"
However I did many System.out.println()s and got that
System.out.println(FilenameUtils.getExtension(fc.getSelectedFile().getName()));
Prints csv. But still returns false when I enter:
System.out.println(FilenameUtils.getExtension(fc.getSelectedFile().getName()) == "csv");