import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Day04_B {
static ArrayList list;
public static void main(String[] args) {
list = new ArrayList<>();
File dir = new File("K:\\Test");// 文件目录
sum(dir);
}
private static void sum(File dir) {
File[] files = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".txt");
}
});
for (File file : files) {
read(file);
}
for (int j = list.size() - files.length; j < list.size(); j++) {
for (int i = 0; i < list.size() - files.length; i++) {
System.out.println(list.get(i) + list.get(j));
}
}
}
private static void read(File files) {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(files)));
for (String str = br.readLine(); str != null; str = br.readLine()) {
int tem = 0;
String[] strs = str.replaceAll(" ", "").split(",");
for (int i = 0; i < strs.length; i++) {
tem += Integer.valueOf(strs[i]);// 记录数组,递增和
}
list.add(tem);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}