0

HI...

Currently I m working in a application in which application allows to access directory (which contains some files) from file server to Application (client).

I tried following code..

URL url=("http://192.168.5.555/file-server/user/images/");
URI uri=url.toURI();
File list[];

list= new File(uri).listFiles();

But its thrown java.lang.IllegalArgumentException Exception.

I don't know how this happen?

I simply access images directory from the given URL (file server).

Help me...

1
  • What sort of file server? Is it ftp? If it's simply an http server it's possible they don't have indexing turned on so there is no way to get a list of files. Even if they do have indexing turned on I don't know if there is a standard protocol for directory-like access. You may have to read the index file and parse it yourself. Commented Jun 2, 2010 at 13:17

1 Answer 1

1

That isn't going to work. The java.io.File operates on the local disk file system only, i.e. on URI's starting with file:// only. It would otherwise indeed going to be too easy to leech files from places where you aren't allowed to do so.

Check if the server in question supports FTP, then you can just use FTPClient#listFiles() for this. If it doesn't, but it supports directory listing, then you need to parse the HTML response containing the directory listing with a HTML parser like Jsoup and then refire a new request on every found link.

If it doesn't support FTP or directory listing, then you're lost and you're probably trying to do bad things.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.