Solved

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

Posted on 2007-11-15
3
1,909 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cloud File Access 3 60
Can I use QuickBooks Pro with DropBox on Windows 8.1 1 68
Weird DFS behavior... 5 101
Peer-to-Peer file sharing Windows 10 Home 4 102
With the withdrawal of support for Windows Server 2003 this summer, many clients face the issue of moving away from their 2003 installs. There are a few options out there that many people/companies are selling. But the clients I have, haven't wanted…
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…
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…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now