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("runnin g 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.las tModified( )));
}
}
-------------------------- ------
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/d ata).
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"
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("runnin
for (int i=0; i<files.length; i++) {
File current = new File(files[i]);
System.out.println(current
String.valueOf(current.las
}
}
--------------------------
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/d
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"
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.
> 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ...