Check file extension in Java

后端 未结 8 910
深忆病人
深忆病人 2021-01-01 10:39

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          


        
相关标签:
8条回答
  • 2021-01-01 11:07

    following

    extension != excel
    

    should be

    !excel.equals(extension)
    

    or

    !excel.equalsIgnoreCase(extension)
    

    See also

    • String equals() versus ==
    0 讨论(0)
  • 2021-01-01 11:08

    In my programm i did that

    if(file_name.endsWith(".xls") || file_name.endsWith(".xlsx"))
       // something works with file
    
    0 讨论(0)
提交回复
热议问题