string - Check file extension in Java -


i have import data excel file database , this, check extension of chosen file.

this code:

string filename = file.getname(); string extension = filename.substring(filename.lastindexof(".") + 1, filename.length());  string excel = "xls"; if (extension != excel) {     joptionpane.showmessagedialog(null, "choose 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 get:

choose excel file!

i can't find wrong code, please help.

following

extension != excel 

should be

!excel.equals(extension) 

or

!excel.equalsignorecase(extension) 

see also


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -