简体   繁体   中英

How to list all the files of a directory which is on a remote machine in java?

I have ac code.I need to write a java code which i would then have to convert into a jar file and run from my c code.The purpose of the jar file would be to log into a remote machine and then navigate to a defined path and then list all the files in the specific directory in string format.That is i want to obtain something like String FileNames[] = {"File1","File2",...} so that then i can use the system call available for FTP log in and download to download all the files recursively.

So how do i do that.Any idea?

查看包含FTP实用程序的Apache commons-net

这就是您所需要的,看看它: http : //docs.oracle.com/javase/6/docs/api/java/io/File.html

ArrayList<String> list = new ArrayList<String>();

public void recursive_file(String path) {
File theFolder = new File(path);
File temp;
String[] theFiles = path.list();

for (int i=0; i<theFiles.length; i++) {
    theFiles[i]=path+theFiles[i];
    temp=new File(theFiles[i]);
    if (temp.isDirectory()) {
        recursive_file(theFiles[i]);
        }
    else { list.add(theFiles[i]); 
         }
    }
}

Something like this? Not sure it's the most elegant solution. You might also need to append a "/" or "\\" on your path String depending on how it's given to the method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM