欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java查看某路径下的文件夹列表,并判断文件夹的最后修改时间

程序员文章站 2022-05-24 12:31:00
...
public static List<String> readfile1(String filepath) throws FileNotFoundException, IOException {
		List<String> list = new ArrayList<>();
		try {

			File file = new File(filepath);
			if (file.isDirectory()) {
				// System.out.println("文件夹");
				String[] filelist = file.list();
				for (int i = 0; i < filelist.length; i++) {
					File readfile = new File(filepath + "\\" + filelist[i]);
					if (readfile.isDirectory()) {
						readfile(filepath + "\\" + filelist[i]);
						System.out.println("path=" + filepath + "\\" + filelist[i]);
						File f = new File(filepath + "\\" + filelist[i]);
						Calendar cal = Calendar.getInstance();
						long time = f.lastModified();
						SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						cal.setTimeInMillis(time);
						System.out.println("修改时间 " + formatter.format(cal.getTime()));
					}
				}

			}
			// System.out.println(list.size());
			return list;
		} catch (FileNotFoundException e) {
			System.out.println("readfile()   Exception:" + e.getMessage());
		}
		System.out.println("ok");
		return list;

	}

 

最后输出的是文件夹列表信息和文件夹的修改时间!!!