title: Reading from text-file in Java
body: <p>I have some serious problems getting my program to read in the right values and storing them in the right place. I have been staring on this problem for 3 hours straight and tried everything, but it doesn't fix the problem.</p>
  
  <p>I am writing a program that reads a sudoku-board from a text-file and creates the same sudoku board where the values given is stored in boxes, rows and columns. My program is doing all this, <strong>but not the rows and columns part.</strong> </p>
  
  <p>Input txt-file example:</p>
  
  <pre><code>4
  2
  .32..1
  1..6..
  37....
  6..1..
  ......
  4..2..
  </code></pre>
  
  <p>The first line is number of rows in a box and the second line is columns.
  Then the program reads one line at the time and store the values one by one in the right place on the board and the right box. But the rows and columns is giving the last values read, like this: (zero is a blank space)</p>
  
  <pre><code>row[0]:400200 (should be:032001)  column[0]:100000 (should be: 013604)
  row[1]:400200 (100600)            column[1]:100000 (307000)
  row[2]:400200 (and so on...)      column[2]:100000 (and so on...)
  row[3]:400200                     column[3]:100000
  row[4]:400200                     column[4]:100000
  row[5]:400200                     column[5]:100000
  </code></pre>
  
  <p>This is the part of my program that struggles, I have tried a lot of different things, and it might look messy, but I tried to clean it up a bit for you guys!</p>
  
  <pre><code>public static Brett lesFil(String filnavn) throws Exception {
          Scanner fil = new Scanner(new File(filnavn));
          String linje;
  
          int antRad = Integer.parseInt(fil.nextLine());
          int antKol = Integer.parseInt(fil.nextLine());
  
          //number of rows and columns on the board.
          int antRaKo = antRad * antKol;
  
          //number of boxes on the board.
          int antBoks = (antRaKo * antRaKo) / (antRad * antKol);
  
          //tools to help the program create boxes the right way.
          int radShift = 0;
          boolean kolShiftEnabler = true;
  
          Brett nyttBrett = new Brett(antBoks, antRaKo, antRad, antKol);
  
      //Creates the row and column objects.
      for(int i = 0; i &lt; antRaKo; i++) {
          nyttBrett.rader[i] = new Rad(antRaKo);
          nyttBrett.kolonner[i] = new Kolonne(antRaKo);
      }
      //i is the row.
      for(int i = 0; i &lt; antRaKo; i++) {
              //Creates boxes.
              if(i == radShift) {
                  radShift = radShift + antRad;
                  nyttBrett.bokser[i/antRad][0] = new Boks(antRad, antKol);
                  kolShiftEnabler = true;
              }
  
              linje = fil.nextLine();
              int kolShift = antKol;
  
              //j is the column.
              for(int j = 0; j &lt; antRaKo; j++) {
                  //Creating boxes.
                  if(j == kolShift &amp;&amp; kolShiftEnabler) {
                      kolShift = kolShift + antKol;
                      nyttBrett.bokser[i/antRad][j/antKol] = new Boks(antRad, antKol);
                  }
  
                  //Creating pointers from tile to box, row, column and tile on my board, and the other way around.
                  Rute nyRute = new Rute(tegnTilVerdi(linje.charAt(j)));
                  nyttBrett.ruter[i][j] = nyRute;
                  nyRute.rad = nyttBrett.rader[i];
                  nyttBrett.rader[i].ruter[j] = nyRute;
                  nyRute.kol = nyttBrett.kolonner[j];
                  nyttBrett.kolonner[j].ruter[i] = nyRute;
                  //Pointing the tiles to the box, don't worry about it.
                  nyttBrett.ruterIBoks(nyRute,i,j);
              }
              //Tool to create boxes.
              kolShiftEnabler = false;
          }
  </code></pre>
  
  <p>Edit: The classes are norwegian, I did not rewrite them because it shouldn't impact the ability to find the problem.</p>
  
  <p>Edit2: Just reminding you that it doesn't break. 
  It does not store the right values in the right row/column, it overwrites the previously stored array with the last row/column of data.</p>