如何读取桌面文件夹和文件.........我的下面程序读取所有文件(也在文件夹内)

时间:2014-02-04 16:23:35

标签: java

我希望在桌面上阅读文件+文件夹快捷方式 凭借其创建日期和修改/上次访问日期......所以我应该做出哪些更改

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class read {

public static void main(String[] args) {
    List<File> fileList =new ArrayList();
    final File folder = new File("C:\\Users\\ROSH\\Desktop");
    new read().listFilesForFolder(folder, fileList);
}

public void listFilesForFolder(final File folder,List<File> fileList) {
    File[] filesInFolder = folder.listFiles();

    if (filesInFolder != null) {
        for (final File fileEntry : filesInFolder) {
            if (fileEntry.isDirectory()) {
                System.out.println("DIR : "+fileEntry.getName());
                listFilesForFolder(fileEntry,fileList);
            } else {
                System.out.println("FILE : "+fileEntry.getName());
                fileList.add(fileEntry);
            }
        }
    }
}

0 个答案:

没有答案