打开共享文件夹可以用 file.getFiles() 的方式,别的就不知道了。/**
* 登录网上邻居
* @param host
* @param user
* @param pass
*/
public void login(String host, String user, String pass){
String info = "net use \\\\" + host + " " + pass + " /user:" + user;
try {
Process process = Runtime.getRuntime().exec(info);
InputStream is = process.getInputStream();
BufferedReader buf = new BufferedReader(new InputStreamReader(is, "gbk"));
String data = null;
while ((data = buf.readLine()) != null){
System.out.println(data);
}
buf.close();
} catch (IOException e) {
System.out.println("login failed: " + e.getMessage());
}
}
/**
* 获取网上邻居中的一个目录列表
*/
public void listFiles(){
String path = "\\\\10.0.113.158\\log";
File file = new File(path);
File[] files = file.listFiles();
for (File f : files){
if (f.isDirectory()){
System.out.println(" dir : " + f.getAbsolutePath());
} else {
System.out.println("file : " + f.getAbsolutePath());
}
}
}
2011年1月20日 15:28