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
}

```
**This is the solution that I would use.** 

```
import java.util.ArrayList;
import java.util.Scanner;
public class Solution1 {

    public static void main(String[] args) throws IOException{
        String nameFile;
        File file;
        Scanner keyboard = new Scanner(System.in);
        int total = 0;

        System.out.println("What is the name of the file");

        nameFile = keyboard.nextLine();
        file = new File(nameFile);

        if(!file.exists()){
            System.out.println("File does not exit");   
            System.exit(0);
        }

        Scanner reader = new Scanner(file);
        while(reader.hasNext()){
            String fileData = reader.nextLine();
            for(int i = 0; i < fileData.length(); i++){
                if(Character.isDigit(fileData.charAt(i))){
                    total = total + Integer.parseInt(fileData.charAt(i)+"");
                }

            }
            System.out.println(total + " \n");
        }

    }

}

```