次のようなテキストファイルがあります。
1 2 3 4 5
6 7 8 9 1
8 3 9 7 1
9 3 4 8 2
8 7 1 6 5
ここで、各番号はタブで区切られています。
私の質問は、Javaを使用して数値の列を合計する簡単な方法はありますか?1 + 6 + 8 + 9 + 8、2 + 7 + 3 + 3+7などを合計したい。次のコマンドを使用してファイルを読み取っています。
public static boolean testMagic(String pathName) throws IOException {
// Open the file
BufferedReader reader = new BufferedReader(new FileReader(pathName));
// For each line in the file ...
String line;
while ((line = reader.readLine()) != null) {
// ... sum each column of numbers
}
reader.close();
return isMagic;
}
public static void main(String[] args) throws IOException {
String[] fileNames = { "MyFile.txt" };
}