Link to home
Start Free TrialLog in
Avatar of Fungushnitzel
Fungushnitzel

asked on

How do I use java.net class to get remote listing of files.

Dear Experts Exchange,
 
the following code list files in a directory, so if I type "javac ListFiles c:\projects" I see all files and directories in "c:\projects".
 
package listfiles;
import java.io.*;
public class Main {
   
    public Main() {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String dir = args.length > 0 ? args[0]: "."; //pass directory to list or current dir
        //Get an array of only text files in the directory.
        String[] files = new File(dir).list();
        System.out.println("running my file listing test");
        for (int i=0; i<files.length; i++) {
            File current = new File(files[i]);
            System.out.println(current.getName()+", "+
            String.valueOf(current.lastModified()));
        }            
    }
   
--------------------------------
I get output like
 
run:
running my file listing test
200300N-1526E.aux, 0
200300N-1526E.tif, 0
atcf, 0
bookstore, 0
------------------------------------------------------------------------------
Questions:
 
I would like to do the same for a URL, so I type "javac ListUrlFiles http:\\www.text.com\data"
 
is see all files in the directory supported by a web server (where http:\\www.txt.com\data is somethign like /usr/local/apache/htdocs/data).
 
1) Can someone show me how to do list all files as a function of URL, with say java.net.*.
 
2) Also, I expected to get a unixtime stamp when calling current.lastModified() but instead getting a "0"
Avatar of ahoffmann
ahoffmann
Flag of Germany image

> see all files in the directory supported by a web server (where http:\\www.txt.com\data
not possible, except the webserver returns a directory listing (which is in HTML format then, obviously)

> expected to get a unixtime stamp
I doubt that you get a unix timestamp on a windoze system ...
Avatar of Fungushnitzel
Fungushnitzel

ASKER

> ahoffmann:> see all files in the directory supported by a web server (where http:\\www.txt.com\data
> not possible, except the webserver returns a directory listing (which is in HTML format then, >obviously)

I'm confused about this answer, in IE and Firefox, I'm able to retrieve a list of files in a given directory even when there is no index file, it stands to reason that if the browser can do this then JAVA can do it as well, correct?



I doubt that you get a unix timestamp on a windoze system ...

Sorry I wasn't clear on this, I'm looking for the file name and date,  so that I can be sure that the files are updated, on an http webserver.  
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial