**
Java获取某个时间段之类的文件或图片
这两天写代码的时候需要完成一个功能,上报一段时间类的图片,
话不多说看代码
public static void disposeXsReport9(List<Map<String, Object>> originData) throws Exception {
List<Map<String, Object>> data = null;
try {
String format = "yyyy-MM-dd HH";
//设置开始时间
Date startTime = new SimpleDateFormat(format).parse("2021-05-16 04");
// 设置结束时间
Date endTime = new SimpleDateFormat(format).parse("2021-07-13 09");
Map<String, File> fileParams = new HashMap<String, File>();
List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
for (int i = 0; i < originData.size(); i++) {
Map<String, Object> curMap = originData.get(i);
Map<String, Object> dataMap = new HashMap<String, Object>();
// 处理attachment
/* String path = (String)curMap.get("PTH"); */
SimpleDateFormat stm = new SimpleDateFormat("yyyy");
String datas = stm.format(new Date());
//设置路径
String path = "D:\\图片数据\\" + datas + "\\" + curMap.get("fadcd") + "\\" + curMap.get("STCD");
int imgtype = (int) curMap.get("imgtype");
String STCD = (String) curMap.get("STCD");
String czcd = (String) curMap.get("hyststats");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
SimpleDateFormat sdfDay1 = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfDay2 = new SimpleDateFormat("yyyy_MM_dd");
SimpleDateFormat sdfDay3 = new SimpleDateFormat("yyyyMMdd");
String curDateStr1 = sdfDay1.format(new Date());
String curDateStr2 = sdfDay2.format(new Date());
String curDateStr3 = sdfDay3.format(new Date());
String path1 = null;
path1 = path;
String curDateStr = sdf.format(startTime);
String cudare=sdf.format(endTime);
// System.out.println(curDateStr);
File stFile = new File(path1);
File[] list = stFile.listFiles();
List<File> files = new ArrayList<File>();
System.out.print(files);
long newestTime = 0;
File newestFile = null;
if (list != null && list.length > 0) {
for (File file : list) {
// System.out.println("filename-------->"+file.getName());
//获取图片最后修改时间
String fileModified = sdf.format(file.lastModified());
Date fileModif1ied = new SimpleDateFormat(format).parse(fileModified);
// System.out.println("fileModified==>"+fileModified);
//设置时间区间
if (fileModif1ied.after(startTime)&&fileModif1ied.before(endTime)) {
//获得时间区间内的图片
files.add(file);
}
}
// 如果当前日期没有图片。获取当天最新一张
/*
* if(files.size()<=0&&null!=newestFile) { files.add(newestFile); }
*/
}
}