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

public static List readfile1(String filepath) throws FileNotFoundException, IOException {
		List 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;

	}

 

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

你可能感兴趣的:(java开发,存储过程,java,文件夹时间)