title: How would I read the following text into a 2D Array
body: <p>Once written to text file the 2D object looks like this:</p>
  
  <pre><code>null null -5 160 2 null null
  null 75 80 1 75 160 0 null 75 320 1 
  null null 155 160 2 null null 
  235 0 1 235 80 2 235 160 1 null null
  </code></pre>
  
  <p>the object is in the form </p>
  
  <pre><code>elements(x,y,i)
  </code></pre>
  
  <p>So each object makes use of 3 digits. </p>
  
  <p>The problem arises in reading the Integers from the text file as it is mixed with the String from the "null values."
  This is what I have so far but it only partially reads the text file.</p>
  
  <pre><code>    public void readElements() throws IOException {
          File file = new File("elements.txt");
          Scanner inp = new Scanner(file);
  
  
          for (int col = 0; col &lt;rectArr.length; col++){
  
              if(inp.hasNextLine()) {
                  inp.nextLine();
              }
  
              for(int row = 0; row&lt;rectArr[0].length; row++){
                 if(inp.hasNext()) {
                     try {
                         String s = inp.next();
                         Integer.parseInt(s);
  
                         System.out.println(s);
  
                         int x = Integer.parseInt(s);
                         int y = Integer.parseInt(inp.next());
                         int i = Integer.parseInt(inp.next());
  
                         elementsArr[col][row] = new elements(x, y, i);
  
                     } catch (NumberFormatException nfe) {
  
                     }
                 }
              }
          }
     }
  </code></pre>