为什么一段时间后就运行不下去了?

bjmylihui 2005-01-05 09:07:25

任务是对大量数据进行分析,"D:/log"目录下有200多个文本文件,很大,甚至一个就有60M,每一行的数据都是有固定格式的,其中带有时间信息,我要做的就是计算04年每个月含有deal ***的数量,大家看看,为什么运行一段时间后,就不走了,文件是按月份排列的,运行的9月份的时候停下来的。


import java.io.*;

public class Trip {
public Trip() {
}
public static int[] statics() throws Exception {
String path = "D:/log";
int[] result = new int[13];
for (int i = 0; i < result.length; i++) {
result[i] = 0;
}
File dir = new File(path);
File[] files = dir.listFiles();
//FileInputStream in=null;
FileReader reader = null;
BufferedReader in = null;

for (int i = 0; i < files.length; i++) {
if (!files[i].isDirectory()) {
try {
System.out.println("i="+i+" :"+files[i].getCanonicalPath());
reader = new FileReader(files[i]);
in = new BufferedReader(reader);
String line = null;
while ( (line = in.readLine()) != null) {
System.out.println(line);
if (! (line.trim().length() <= 0) && line.indexOf("deal ***") != -1) {
//2004-02-25
if (line.charAt(3) == '4') {
String[] temp = line.split("-");
// System.out.println(temp[1]);
int month = new Integer(temp[1]).intValue();
System.out.println(month);
result[month]++;

}
}

}
in.close();
reader.close();

}
catch (Exception e) {
e.printStackTrace();
}

}

}

return result;

}

public static void main(String[] args) throws Exception {

int[] ret = Trip.statics();
File f = new File("g:/log.txt");
FileOutputStream out = new FileOutputStream(f);
for (int i = 0; i < ret.length; i++) {

String temp = i + "月份: " + ret[i];
System.out.println(i + "月份: " + ret[i]);
out.write(temp.getBytes());
}


}

}
...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
miaoliujun 2005-01-05
  • 打赏
  • 举报
回复
把不必要的system.out去掉
miaoliujun 2005-01-05
  • 打赏
  • 举报
回复
你将
in.close();
reader.close();
改为
in.close();
in = null;
reader.close();
reader = null;

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧