title: How to sort a large text file's data into a multi-dimensional array?
body: <p>I have a very large data file. It starts off with a big paragraph that I want to ignore or remove from the equation, then it has a year e.g. 1974, then 6 spaces, then a number to represent a month, e.g. 1, then it has 31 data entries that I want to sort into a 3D array.</p>
  
  <p>I think I'm close to solving it, but I keep getting the exception <code>java.lang.ArrayIndexOutOfBoundsException</code>.</p>
  
  <p>Full error is:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 31
        at pkg110_term3.GetData.readFile(GetData.java:48)
        at pkg110_term3.Main.main(Main.java:25)
    Java Result: 1</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>public class GetData {
  
      public String[][][] sortedData = new String[34][12][31];
  
      int a = 0;
      int b = 0;
      int c = 0;
  
      private Scanner rainFile;
  
      //method for opening the file
      public void openFile() {
  
          try{
              rainFile = new Scanner(new File("C:\\\\Users\\\\admin\\\\Documents\\\\NetBeansProjects\\\\110_term3\\\\WeatherDataFiles\\\\rainfall.txt"));
          }
          catch(Exception e){
              JOptionPane.showMessageDialog(null, "Check the file path is correct.", "No file found!", JOptionPane.ERROR_MESSAGE);
          }
      }
  
      //method for reading the file
      public void readFile(){
  
          if(rainFile.equals("Daily Rainfall Totals (mm), Hazelrigg Weather Station, Lancaster University (Meteorological Office Climatological Station Number 7236) \n" +
  "Brian Davison, LEC, Lancaster University, data obtained March 2012 \n" +
  "Format=Year, Month, 1-31 daily precipitation values. Any entry set to -99.99 means that no data exists for that day. ")){
              rainFile.remove();
          }
          while(rainFile.hasNext()){
              rainFile.next();
              a++;
              while(rainFile.hasNext()){
                  rainFile.next();
                  b++;
                  for(int i = 0; i &lt; 31; i++){
                      String day = rainFile.next();
                      sortedData[a][b][c] = day;
                      c++;
                  }
              }
          }           
          }
  
          //close the file once it's been used
          public void closeFile(){
              rainFile.close();
          }
  
  
          //test method to see if array is full
          public void arrayTest(){
              System.out.print(sortedData[0][0][0]);
              System.out.print("\n");
              System.out.print(sortedData[0][1][0]);
              System.out.print("\n");
          }
  
  }
  </code></pre>
  
  <p>I did ask a similar question recently but my code has changed quite a bit since.</p>
  
  <p>Thanks in advance.</p>
  
  <p>First 2 years of rainfall data + the paragraph I want to get rid of:</p>
  
  <pre><code>Daily Rainfall Totals (mm), Hazelrigg Weather Station, Lancaster University (Meteorological Office Climatological Station Number 7236) 
  Brian Davison, LEC, Lancaster University, data obtained March 2012 
  Format=Year, Month, 1-31 daily precipitation values. Any entry set to -99.99 means that no data exists for that day. 
  1974      1   0.00   0.00   1.70   3.30   8.70   2.30  12.70  13.10   0.01  13.50   1.50   5.50   1.90  15.40   6.50   7.70   4.00   0.10   0.00   0.00   0.00   8.00   0.20   0.01   0.01   7.00   8.00   0.20   2.30   7.00   0.20
  1974      2   6.60  14.90   0.70   5.00   7.30   0.80   0.20   9.40   5.50  10.50   5.50   2.50   0.80   6.90   2.50   0.30   0.00   0.01   0.00   1.80   0.40   0.00   0.00   0.20   0.01   0.01   0.01   7.40 -99.99 -99.99 -99.99
  1974      3   2.20   0.00   0.60   0.60   0.00  12.80   0.01   0.01   0.01   0.10   0.01   0.00   0.50   3.70   6.80   2.50   9.10   1.50   0.01   0.01   0.00   0.00   0.00   0.20   0.20   0.00   0.00   0.00   0.00   0.00   0.00
  1974      4   0.00   0.01   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.70   0.80   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.01   0.00   0.00 -99.99
  1974      5  35.60   0.90   0.60   0.00   0.01   0.00   0.00   0.10   4.50   2.40   0.01   2.70   3.00   0.00   0.00   0.01   0.01   1.20   1.30   3.10   1.00   7.40   7.30   0.01   0.01   0.01   1.00   4.10   0.00   0.00   0.01
  1974      6   1.80   0.01   0.00   0.01  15.50   8.80   3.90   3.50   2.20   5.90   0.00   0.00   0.00   0.00   5.20   4.00   0.01   6.20   0.01   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.00   0.00  16.70 -99.99
  1974      7   0.01  32.30   3.70  16.40   0.01   1.70   0.10   0.20   2.90   1.80   0.01   0.00   0.10  11.50  16.00   2.20   0.01   0.80   5.20   0.00   0.01  10.00   0.10   0.00   6.80   0.00   4.00   1.30  15.00   9.20   4.20
  1974      8   0.00   0.00   0.00   0.00   0.00   0.00   0.10   7.30  19.40   4.40  16.40   0.01   0.10   5.60   0.00   1.20   0.00   0.00   0.00   0.00   1.00   1.70   0.10   0.20   3.80   7.60   0.01   0.00   0.01   0.00   5.50
  1974      9   1.40   7.60   3.90  29.80  12.90  12.80  16.80  22.40   1.10   0.01   0.50  12.00   0.01   0.50   0.20   8.50   0.01   0.00   1.20   8.80   1.40  12.70   7.90  19.80   2.20   0.70  16.40   0.00   0.01   0.01 -99.99
  1974     10  12.30   0.20   6.20   0.01   0.01  11.30   0.20   0.00   0.00   0.10   0.00   0.00   0.00   0.01   5.10   0.01   4.20  16.80   8.30   0.50   0.01   0.01   0.00   0.70   0.20   2.70   1.10   0.00   0.00   4.30   2.40
  1974     11   0.01   8.40   0.80   0.00   0.90   0.20   9.10   2.60   6.00  11.60   6.00   2.30  15.60   6.40   3.20   0.01   0.00   0.00   2.50   0.01   0.30   1.60   5.60  11.50   2.30   0.90   3.40   0.01   8.10   2.10 -99.99
  1974     12   0.80   0.30   2.30   0.90   0.01   0.60   7.80   1.20   5.90   8.70   4.80   1.20   4.00   0.00   7.80   5.20   5.20   1.80   0.00   4.30   2.30   0.01   7.80   2.70  10.00   2.00   3.80   1.60   0.50   1.50   0.00
  1975      1   3.30   1.40   0.01   2.20   0.10  16.80   4.70   0.40   0.10   5.70   1.60   7.60   1.80   4.00   2.10  10.70   7.20   1.00   6.80   4.30  25.10  10.20   0.20  13.20   3.30   6.70   2.10   0.70   2.10   8.20   5.90
  1975      2   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   3.10   0.80   1.60   6.80   1.70   0.00  16.00   0.20   0.00   0.00   0.90   0.00   0.00   2.50   0.00   0.00   0.00   0.00   0.00 -99.99 -99.99 -99.99
  1975      3   0.50   2.20   0.50   9.90   0.00   6.90   0.00   0.00   0.01   0.10   0.10   0.00   0.00   0.01   0.00   0.01   0.01   0.01   0.00   0.00  15.60   0.01   0.00   0.01   8.80   1.10   0.01   0.00   0.20   1.00   0.00
  1975      4   2.80   0.01   0.01   0.01   0.01   3.10   0.01   0.01   0.40   4.40   2.40   1.20   2.00   7.80   0.10   5.40   3.60   6.20   1.80   7.60   2.80   0.10   0.10   0.00   0.00   0.00   0.00   5.40   0.30   8.00 -99.99
  1975      5   2.10   0.01   0.00   0.00   0.00   0.00   1.20   4.80   1.80   0.80   0.10   2.10   5.20   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.01   0.01   0.00   0.00   0.00   0.00   0.20   0.00
  1975      6   3.10   1.90   3.40   5.60   4.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.10   0.00   0.40   0.00   0.01   1.10   1.50   1.40   0.00   0.00   0.00   0.01   0.00   0.00   0.00   0.00   0.00   0.00 -99.99
  1975      7   0.00   0.00   0.01   0.01   0.00   0.00   0.01   0.10   7.20   7.90   0.01   5.50   5.90  18.10   0.01   0.00   7.00   0.01   4.10   2.20  15.60  32.80   2.50   7.20   2.50   0.01   0.00   0.01   0.01   0.01   0.00
  1975      8   0.00   0.00   0.00   2.80   2.70   0.00   1.30   5.80   3.60   0.00   0.00   0.01   0.00  11.40  26.70   0.30   0.00   0.01   5.20   0.20   8.00   0.00   0.80   4.60   0.00   0.00   0.00   0.00   7.50   0.50   0.00
  1975      9   0.00   0.40   0.01   5.40   2.00   0.90   1.30   9.70  13.70  23.50  18.90   0.20   0.00   0.00   0.00   0.00   6.90   0.30   3.80   1.80   0.00   7.40   0.60  32.00   5.60   3.40  13.50   0.00   4.60  19.90 -99.99
  1975     10   8.30  21.10   0.20   5.00   0.20   0.00   0.00   0.01   1.80   0.00   0.00   0.00   0.01   0.10   1.20   1.20   0.00   0.00   0.00   0.00   0.00   0.01   6.00   0.00   0.01   0.00   0.00   0.00   0.01   0.40   3.20
  1975     11   8.20   9.70   0.01   8.70   4.90   0.01   0.00   0.00   0.50   0.40   0.10   0.00   0.00   5.80  17.50   0.01   0.00   4.60   3.00   0.00   0.00   0.20   5.00   4.20  11.50   6.80   7.20   0.01   3.10   5.00 -99.99
  1975     12  43.20   0.01   0.01   0.01   0.01   0.40   0.01   0.01   0.01   0.01   3.20   0.00   0.01   0.00   0.01   0.20   0.00   1.30   0.20   0.01   0.01   0.01   3.10   8.40   0.01   0.01   0.80   0.10   0.40   3.20  10.70
  </code></pre>
  
  <p>I've just realised that each month is separated by a line, could I use that to make sorting it easier?</p>