vondip vondip - 9 months ago 60
Java Question

Reading a remote file using Java

I am very new to java, and have been struggling with it. I am looking for an easy way to get files that are situated on a remote server. For this I created a local ftp server on my windows xp, and now I am trying to give my test applet the following address:

uri = new URI("ftp://localhost/myTest/test.mid");
File midiFile = new File(uri);
catch (Exception ex)

and of course I receive the following error:
URI scheme is not "file"

I've been trying some other ways to get the file, they don't seem to work. Any insight of how I should do it? This should be straight forward shouldn't it? (BTW, I am also keen to perform an http request)


You can't do this out of the box with ftp.

If your file is on http, you could do something similar to:

URL url = new URL("http://q.com/test.mid");
InputStream is = url.openStream();
// Read from is

If you want to use a library for doing FTP, you should check out Apache Commons Net