URI scheme is not "file"

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-05-16T11:37:40Z Indexed on 2010/05/16 11:50 UTC
Read the original article Hit count: 285

Filed under:
|
|
|

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

The url I am playing with is ... and it very much is a file

http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/domefisheye/ladybug/fish4.jpg

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

I have a String called "url", from thereon here is my code:

url = Streams.asString(stream); //gets the URL from a form on a webpage
System.out.println("This is the URL: "+url);
URI fileUri = new URI(url);

File fileFromUri = new File(fileUri);                   

onlyFile = fileFromUri.getName(); 
URL fileUrl = new URL(url);
InputStream imageStream = fileUrl.openStream();
String fileLoc2 = getServletContext().getRealPath("pics/"+onlyFile);

File newFolder = new File(getServletContext().getRealPath("pics"));
    if(!newFolder.exists()){
        newFolder.mkdir();
    }
    IOUtils.copy(imageStream, new FileOutputStream("pics/"+onlyFile));
} 

The line causing the error is this one:

File fileFromUri = new File(fileUri);                   

I have added the rest of the code so you can see what I am trying to do.

© Stack Overflow or respective owner

Related posts about java

Related posts about servlet