How to determine the file extension of a file from a uri

后端 未结 8 1857
一向
一向 2020-12-13 19:06

Assuming I am given a URI, and I want to find the file extension of the file that is returned, what do I have to do in Java.

For example the file at http://www.daml.

8条回答
  •  醉话见心
    2020-12-13 19:46

    I am doing it in this way.

    You can check any file extension with more validation:

    String stringUri = uri.toString();
    String fileFormat = "png";
    
                        if (stringUri.contains(".") && fileFormat.equalsIgnoreCase(stringUri.substring(stringUri.lastIndexOf(".") + 1))) {
    
                            // do anything
    
                        } else {
    
                            // invalid file
    
                        }
    

提交回复
热议问题