Solved

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

Posted on 2007-11-15
3
1,911 Views
Last Modified: 2013-11-22
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"
0
Comment
Question by:Fungushnitzel
  • 2
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 20297802
> 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 ...
0
 

Author Comment

by:Fungushnitzel
ID: 20301009
> 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.  
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 20303774
> .. in IE and Firefox, I'm able to retrieve a list of files
this has nothing to do with the browser, but the server
If you connect to a server useing http:// that server has to be configured to return a directory listing if requested.
The browser can do it and java can do it and any other thing can do it also as long as the server is configured for it. Dot.

> .. so that I can be sure that the files are updated, ..
sounds like you try to reenvent the wheel, is http://rsync.samba.org/ probably what you want to do?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
As a financial services provider, your business is impacted by two of the strictest federal regulations on record: the Sarbanes-Oxley Act and the Gramm-Leach-Bliley Act. Correctly implementing faxing into your organization to provide secure, real-ti…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question