2014年12月2日 星期二

JAVA 遞迴走訪目錄



private void retrievalFolder(String path) throws Exception {
    try {
        File main = new File(path);
        if (main.isDirectory()) {
            String[] filename = main.list();
            for (int i = 0; i < filename.length; i++) {
                File sub = new File(main.getAbsoluteFile() + File.separator + filename[i]);
                if (sub.isDirectory()) {
                    this.retrievalFolder(main.getAbsoluteFile() + File.separator + filename[i]);
                } else {
                    //TODO
                }
            }
        } else {
            //TODO
        }
    } finally {
        //TODO
    }
}

沒有留言:

張貼留言