How do I list file names on a server in a directory?

Suhail Gupta

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.

Martijn Courteaux

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.

Collected from the Internet

Please contact debug[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I change directory and run a file in that directory in powershell?

From Dev

Inno Setup: List all file names in an directory

From Dev

python 2.7 - How do I save images to a directory from a list of URLs in a CSV file

From Dev

How do I handle file names with spaces?

From Dev

How to list only the file names and not its attributes in a directory( in Linux)?

From Dev

How do I sort a list of file names in the Windows command prompt?

From Dev

How to build a list of file names in a local directory?

From Dev

How can I obtain all of the file names in a directory?

From Dev

How do I create a .bat file that will make iterative file names?

From Dev

How can I format a list of files with directory names in unix?

From Dev

How can I retrieve a list of SQL Server LocalDb names?

From Dev

How do I navigate to folders with spaces in their names? I get "no such file or directory" when I try

From Dev

How do I decode a list of base64-encoded file names?

From Dev

How do I list every file in a directory except those with specified extensions?

From Dev

How do I navigate to folders with spaces in their names? I get "no such file or directory" when I try

From Dev

How do I change default folder names in home directory?

From Dev

How do I create a directory for every file in a parent directory

From Dev

How to list only the file names of the same type in the directory?

From Dev

How can I recursively replace a string in file and directory names?

From Dev

How do I touch every file in a directory?

From Dev

In R: How do I get the column names of a CSV file as a list and values as a list of lists

From Dev

How do I sort a list of file names in the Windows command prompt?

From Dev

How do i list the full path of certain file type in a directory and its subdirectories?

From Dev

How do I Sort the names in a Linked List?

From Dev

How can I fetch a list of file names from a Remote Server via FTP?

From Dev

How to list directory names that do not contain a certain filename?

From Dev

Download list of directory/file names only from web server index

From Dev

How do I cd the remote server directory mounted through File/Nautilus?

From Dev

How do I zip a SQL Server backup file using Powershell and save in the same directory?

Related Related

  1. 1

    How do I change directory and run a file in that directory in powershell?

  2. 2

    Inno Setup: List all file names in an directory

  3. 3

    python 2.7 - How do I save images to a directory from a list of URLs in a CSV file

  4. 4

    How do I handle file names with spaces?

  5. 5

    How to list only the file names and not its attributes in a directory( in Linux)?

  6. 6

    How do I sort a list of file names in the Windows command prompt?

  7. 7

    How to build a list of file names in a local directory?

  8. 8

    How can I obtain all of the file names in a directory?

  9. 9

    How do I create a .bat file that will make iterative file names?

  10. 10

    How can I format a list of files with directory names in unix?

  11. 11

    How can I retrieve a list of SQL Server LocalDb names?

  12. 12

    How do I navigate to folders with spaces in their names? I get "no such file or directory" when I try

  13. 13

    How do I decode a list of base64-encoded file names?

  14. 14

    How do I list every file in a directory except those with specified extensions?

  15. 15

    How do I navigate to folders with spaces in their names? I get "no such file or directory" when I try

  16. 16

    How do I change default folder names in home directory?

  17. 17

    How do I create a directory for every file in a parent directory

  18. 18

    How to list only the file names of the same type in the directory?

  19. 19

    How can I recursively replace a string in file and directory names?

  20. 20

    How do I touch every file in a directory?

  21. 21

    In R: How do I get the column names of a CSV file as a list and values as a list of lists

  22. 22

    How do I sort a list of file names in the Windows command prompt?

  23. 23

    How do i list the full path of certain file type in a directory and its subdirectories?

  24. 24

    How do I Sort the names in a Linked List?

  25. 25

    How can I fetch a list of file names from a Remote Server via FTP?

  26. 26

    How to list directory names that do not contain a certain filename?

  27. 27

    Download list of directory/file names only from web server index

  28. 28

    How do I cd the remote server directory mounted through File/Nautilus?

  29. 29

    How do I zip a SQL Server backup file using Powershell and save in the same directory?

HotTag

Archive