0

I am trying to get the names of all the directories and files that inside the tpo directory on some server but as I run the following code:

public static void main(String args[]) {
    try {
        File file = new File(new URI("http://xxx/tpo/"));
        String list[] = file.list();
        for(String name : list) {
            System.out.println(name);
        }
    }catch(Exception exc) {
        exc.printStackTrace();
     }
}

I get the following exception :

java.lang.IllegalArgumentException: URI scheme is not "file"
at java.io.File.<init>(File.java:366)
at hack.List.main(List.java:17)

Why is that ? How do I get the file names and the names of the directories inside the tpo directory.

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

2 Answers2

2

You can't. The webserver gives you an html page that contains a list of files if he wants to. If he doesn't, then you have to login via FTP into the server. The error message:

java.lang.IllegalArgumentException: URI scheme is not "file"

Says exactly what is wrong. java.io.File is meant for offline files on your local harddrives/usb devices.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
-1

Maybe you get the wrong point.You may try to return a list that containing the file name in the remote server.Then you can do anything with the file name.

Such as:

return new File("xxx").listFiles();

Then you receive the list,do anything you want.

Royshun
  • 36
  • 8