java 循环日期 按日期递归读取文件夹中的文件,输出到txt文档

public Map editSmsOrder(ComSvcCaller svcCaller) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

Map map = new HashMap();

String start = "20140101";

String path = "E:/Control/smsemail/程序脚本";

String str = "";

try {

FileWriter fileWriter = new FileWriter(

"C:/Users/Administrator/Desktop/list.sql");

Date startDate = null;

try {

startDate = sdf.parse(start);

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Date endDate = new Date();

Calendar ca = Calendar.getInstance();

Date curDate = startDate;

while (curDate.compareTo(endDate) <= 0) {

ca.setTime(curDate);

str = sdf.format(curDate);

int fileNum = 0, folderNum = 0;

File file = new File(path);

if (file.exists()) {

LinkedList<File> list = new LinkedList<File>();

File[] files = file.listFiles();

for (File file2 : files) {

if (file2.isDirectory()) {

if (file2.getAbsolutePath().contains(str)) {

fileWriter.write("@" + file2.getAbsolutePath()

+ "\r\n");

}

list.add(file2);

fileNum++;

} else {

if (file2.getAbsolutePath().contains(str)) {

fileWriter.write("@" + file2.getAbsolutePath()

+ "\r\n");

}

folderNum++;

}

}

File temp_file;

while (!list.isEmpty()) {

temp_file = list.removeFirst();

files = temp_file.listFiles();

for (File file2 : files) {

if (file2.isDirectory()) {

if (file2.getAbsolutePath().contains(str)) {

fileWriter.write("@"

+ file2.getAbsolutePath() + "\r\n");

}

list.add(file2);

fileNum++;

} else {

if (file2.getAbsolutePath().contains(str)) {

if (file2.getAbsolutePath().contains(str)) {

fileWriter.write("@"

+ file2.getAbsolutePath()

+ "\r\n");

}

folderNum++;

}

}

}

}

} else {

System.out.println("文件不存在!");

}

System.out.println("文件夹共有:" + folderNum + ",文件共有:" + fileNum);

ca.add(ca.DATE, 1);

curDate = ca.getTime();

}

fileWriter.flush();

fileWriter.close();

} catch (IOException e1) {

}

return map;

}

 

转载于:https://www.cnblogs.com/wu1254/p/6774409.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值