日期:2014-05-20 浏览次数:20790 次
package com.whale.empire; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class ReadFile { @SuppressWarnings({ "null", "unchecked" }) public void readFile(String path) throws IOException{ File fl = new File(path); File list[] = fl.listFiles(); String fileName; int [] num = null; int maxIndex = 0; for(int i=0;i<list.length;i++) { if(list[i].isFile()) { fileName = list[i].getName(); int k = fileName.lastIndexOf("."); if((k>-1)&&(k<(fileName.length()))) { num[i] =Integer.parseInt(fileName.substring(k-4,k)); } } } for(int j=0;j<num.length;j++) { int max = num[0]; if(num[j]>max) { max=num[j]; maxIndex = j; } } File file = new File(path+"/"+(list[maxIndex]).getName()); BufferedReader br = new BufferedReader(new FileReader(file)); String currentLine; @SuppressWarnings("rawtypes") ArrayList al = new ArrayList(); while((currentLine = br.readLine())!=null) { al.add(currentLine); } } }