I'm trying to read data from a text file that looks something like

United States

I need to add all the numbers after each country together. I also need to which country has the highest number in the third line of each set of three.

Any tips would be great.
Thanks in advance.

Re: Reading data from a text file using scanner 80 80

What I'm basically trying to do is sum up the number in each second line of the set of three.

This is what I have:

public static void main( String[] args) throws Exception
      File stats = new File("C:\\data.txt");
      Scanner fI = new Scanner(stats);

      int sum = 0;
      while(fI.hasNextInt()) {
          sum = fI.nextInt() + sum;
        System.out.println( sum );
Re: Reading data from a text file using scanner 80 80

If the data always comes in groups of three lines, read the three lines, process the data for the three lines and then read the next group of three lines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.