Check file extension in Java

后端 未结 8 944
深忆病人
深忆病人 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 10:54

    == tests referentially equality. For value equality test, use .equals. Use String#equalsIgnoreCase if you want the case to be disregarded during the equality test.

    Another thing: Don't reinvent the wheel, unless it's badly broken. In your case, you should be using Apache Commons' FilenameUtils#isExtension to check the extension.

提交回复
热议问题