Below is the program that prints all the files & folders from the given path.
import java.io.File;
public class ListDirectoryRecursive{
public static void listRecursive(File dir){
if(dir.isDirectory()){
File[] items = dir.listFiles();
for(File item : items){
System.out.println(item.getAbsoluteFile());
if(item.isDirectory()){
listRecursive(item);
}
}
}
}
public static void main(String[] args){
/* Unix path is: /usr/home/david/workspace/JavaCode */
File dir = new File("C:\\Users\\david\\workspace\\JavaCode");
listRecursive(dir);
}
}
How do i make this java program run on Unix? What is the standard approach to make this program portable?
Edit: I guess, we know on any OS, user home directory is part of the environment setting with values like "c:\users\david" in windows and "/user/home/david" in Unix.