Summing columns of a txt file in java
<p>I have a text file that reads:</p>

<p>1 2 3 4 5</p>

<p>6 7 8 9 1</p>

<p>8 3 9 7 1</p>

<p>9 3 4 8 2</p>

<p>8 7 1 6 5</p>

<p>where each number is separated by a tab.</p>

<p>My question is, is there a simple way to sum the columns of numbers using java? I want it to sum 1+6+8+9+8, 2+7+3+3+7, etc. I am reading the file using:</p>

<pre><code> 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" };
</code></pre>

<p>}</p>
