?
Solved

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

Posted on 2007-11-15
3
Medium Priority
?
1,914 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
Outsource Your Fax Infrastructure to the Cloud (And come out looking like an IT Hero!) Relative to the many demands on today’s IT teams, spending capital, time and resources to maintain physical fax servers and infrastructure is not a high priority.
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…
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…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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