I have to import data from an Excel file to database and to do this, I would like to check the extension of the chosen file.
This is my code:
String filename = file.getName();
String extension = filename.substring(filename.lastIndexOf(".") + 1, filename.length());
String excel = "xls";
if (extension != excel) {
JOptionPane.showMessageDialog(null, "Choose an excel file!");
}
else {
String filepath = file.getAbsolutePath();
JOptionPane.showMessageDialog(null, filepath);
String upload = UploadPoData.initialize(null, filepath);
if (upload == "OK") {
JOptionPane.showMessageDialog(null, "Upload Successful!");
}
}
But I always get:
Choose an excel file!
I can't find what is wrong with my code, could someone please help.