Get file name from URL

前端 未结 27 1645
[愿得一人]
[愿得一人] 2020-11-28 02:24

In Java, given a java.net.URL or a String in the form of http://www.example.com/some/path/to/a/file.xml , what is the easiest way to g

27条回答
  •  伪装坚强ぢ
    2020-11-28 03:26

    create a new file with string image path
    
        String imagePath;
        File test = new File(imagePath);
        test.getName();
        test.getPath();
        getExtension(test.getName());
    
    
        public static String getExtension(String uri) {
                if (uri == null) {
                    return null;
                }
    
                int dot = uri.lastIndexOf(".");
                if (dot >= 0) {
                    return uri.substring(dot);
                } else {
                    // No extension.
                    return "";
                }
            }
    

提交回复
热议问题