This week we’re going to work with file.
You’re given a file named
nums.dat and need to calculate the sum of all integer values in the file.
Sum Numbers in File
For this problem you are given a file named
nums.dat that contains integers across multiple lines. There are multiple lines, and there may be 1 or more integers on each line.
calculateSum method, defined below, should return the sum of all integers in the file
As an example, let's say
nums.dat contains the following.
1 3 5 2 122 156
calculateSum should return 289 because \(\large 1 + 3 + 5 + 2 + 122 + 156 = 289\)
Your task is to implement
calculateSum so that it returns the correct value for the entire file.