Solved

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

Posted on 2007-11-15
3
1,913 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Cloud file services can fill many different roles for your business. Often, the use of cloud file services begins with employees using consumer products, like Dropbox, to share files with customers and each other. While sync-and-share can be an effe…
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…

707 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