Tue Apr 05, 2011 8:17 am
Tue Apr 05, 2011 10:02 am
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mailtest.customgui;
import java.io.*;
import java.lang.String;
import java.io.File;
import java.util.*;
import java.util.List;
import java.lang.*;
public class RemoteFileTest {
private File fileObj;
private Map mapfiles;
public RemoteFileTest() {
fileObj = new File("\\\\IPorComputerName\\path");
mapfiles = new HashMap();
mapfiles=printFileInfo(fileObj, mapfiles);
Iterator filesIterator = mapfiles.keySet().iterator();
while (filesIterator.hasNext()) {
String filePath = (String) filesIterator.next();
String fileName = (String) mapfiles.get(filePath);
System.out.println("File name is " + fileName);
System.out.println("File path is " + filePath);
}
}
public static void main(String args[]) {
new RemoteFileTest();
}
/*
*
* Print the content of path , and return a map
* of all files in it .with path and name.
*/
public Map printFileInfo(File fileObj, Map filesMap) {
File[] files = fileObj.listFiles();
// If the current is directory.
if (fileObj.isDirectory()) {
// list for files inside the this directory.
for (int i = 0; i < files.length; i++) {
printFileInfo(files[i], filesMap);
}
} else {
// get the information of fileObj , path is key,name is value to map.
String path = fileObj.getPath();
String name = fileObj.getName();
filesMap.put(path, name);
}
return filesMap;
}
}
Tue Apr 05, 2011 10:05 am
Wed Apr 06, 2011 9:35 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.