我正在使用 Apache commons 并试图从服务器显示指定的文件和目录,有谁知道如何做到这一点,到目前为止,av 使用了这个代码,但它真的不起作用。有人可以帮忙或告诉我哪里出错了。
public String[] getDir(String rootDirectory) {
String server = "192.168.1.11";
int port = 21;
String user = "javaapp";
String pass = "nascalebio";
String Directory = "/cms";
String[] directories;
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
FTPFile[] files = ftpClient.mlistDir(Directory);
directories = new String[files.length];
for (int i =0; i < files.length; i++) {
directories[i] = files[i].getName();
System.out.println(i);
System.out.println(directories[i]);
System.out.println(files.length);
}
return directories;
} catch (IOException e) {
System.out.println(e);
}
return null;
}
public void buildtree(String currentdir, DefaultMutableTreeNode model) throws SocketException, IOException {
String[] currentcrawl = getDir(currentdir);
for (String node : currentcrawl) {
DefaultMutableTreeNode currentnode = new DefaultMutableTreeNode(node);
buildtree(currentdir +"/" + node, currentnode);
model.add(currentnode);
}
buildtree(".", root);
tree.setModel(new DefaultTreeModel(root));