//获取文件夹中所有文件路径
public static List<String> getFileList(String dirPath) {
File dir = new File(dirPath);
File[] fileList = dir.listFiles();
List<String> strList = new ArrayList<String>();
for (File f : fileList) {
if ((f.isFile())
&& (".csv".equals(f.getName().substring(f.getName().lastIndexOf("."), f.getName().length())))) {
strList.add(f.getAbsolutePath());
}
}
return strList;
}
//获取文件夹中最新修改的文件
public static void main(String[] args) {
List<String> listPath = getFileList("E:/test/");
Map<Object, String> map = new HashMap<Object, String>();
for (String path : listPath) {
File f = new File(path);
map.put(f.lastModified(),path);
}
Object[] obj = map.keySet().toArray();
Arrays.sort(obj);
System.out.println(map.get(obj[obj.length - 1]));
}
public static List<String> getFileList(String dirPath) {
File dir = new File(dirPath);
File[] fileList = dir.listFiles();
List<String> strList = new ArrayList<String>();
for (File f : fileList) {
if ((f.isFile())
&& (".csv".equals(f.getName().substring(f.getName().lastIndexOf("."), f.getName().length())))) {
strList.add(f.getAbsolutePath());
}
}
return strList;
}
//获取文件夹中最新修改的文件
public static void main(String[] args) {
List<String> listPath = getFileList("E:/test/");
Map<Object, String> map = new HashMap<Object, String>();
for (String path : listPath) {
File f = new File(path);
map.put(f.lastModified(),path);
}
Object[] obj = map.keySet().toArray();
Arrays.sort(obj);
System.out.println(map.get(obj[obj.length - 1]));
}