Why does the code keep running indefinitely on reading a text file?

Viewed 48

I'm trying to read a txt file into a 2d array. The code keeps running indefinitely. I cannot seem to figure out why.

public static void loadState() throws FileNotFoundException {
    Scanner input = new Scanner(new File("large.txt")); //loads txt file instead of keyboard input for scanner
    int rows = 0;
    int cols = 0;
    while (input.hasNextLine()) {
        ++rows;
        Scanner colReader = new Scanner(input.nextLine());

        while (colReader.hasNextInt()) {
            ++cols;
        }
    }
    input.close();
    System.out.println(cols + "==" + rows);
}
0 Answers
Related