URI scheme is not “file”

后端 未结 2 1297
感情败类
感情败类 2020-12-11 01:41

I get the exception: \"URI scheme is not file\"

What I am doing is trying to get the name of a file and then save that file (from another server) onto my computer/se

2条回答
  •  无人及你
    2020-12-11 01:58

    Your assumption to create File from URL is wrong here.

    You just don't need to create a File from URL to the file in the Internet, so that you get the file name.

    You can simply do this with parsing the URL like that:

    URL fileUri = new URL("http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/domefisheye/ladybug/fish4.jpg");    
    int startIndex = fileUri.toString().lastIndexOf('/');
    String fileName = fileUri.toString().substring(startIndex + 1);
    System.out.println(fileName);
    

提交回复
热议问题