Question: I have a java problem. I am trying to read a txt file which has a variable number of integers per line, and for each line I need to sum every second integer! I am using scanner to read integers, but can't work out when a line is done. Can anyone help pls?

Answer: 
have a look at the [BufferedReader](http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html) class for reading a textfile and at the [StringTokenizer](http://java.sun.com/javase/6/docs/api/java/util/StringTokenizer.html) class for splitting each line into strings.

```
String input;
BufferedReader br = new BufferedReader(new FileReader("foo.txt"));
while ((input = br.readLine()) != null) {
  input = input.trim();
  StringTokenizer str = new StringTokenizer(input);
  String text = str.nextToken(); //get your integers from this string
}

```
or scrape from commons the essentials to both learn good technique and skip the jar:

```
import java.io.*;
import java.util.*;

class Test
{
    public static void main(final String[] args) 
    {

       File file = new File("Test.java"); 

       BufferedReader buffreader = null;
       String line = "";

        ArrayList<String> list = new ArrayList<String>(); 

        try 
            {
                buffreader = new BufferedReader( new FileReader(file) );
                line = buffreader.readLine();
                while (line != null) 
                {
                   line = buffreader.readLine();
                   //do something with line or:
                   list.add(line);
                }
             } catch (IOException ioe) 
             {
                    // ignore
             } finally 
             {
               try 
               {
                  if (buffreader != null) 
                  {
                     buffreader.close();
                  }
               } catch (IOException ioe) 
               {
                    // ignore
               }

            }

           //do something with list
           for (String text : list) 
           {       
               // handle one line
               System.out.println(text);       
           }

   }
}   

```