title: Java Reading 2D array in from file, numbers separated by comma
body: <p>This is some code that I found to help with reading in a 2D Array, but the problem I am having is this will only work when reading a list of number structured like:</p>
  
  <pre><code>73
  56
  30
  75
  80
  ect..
  </code></pre>
  
  <p>What I want is to be able to read multiple lines that are structured like this:</p>
  
  <pre><code>1,0,1,1,0,1,0,1,0,1
  1,0,0,1,0,0,0,1,0,1
  1,1,0,1,0,1,0,1,1,1
  </code></pre>
  
  <p>I just want to essentially import each line as an array, while structuring them like an array in the text file.
  Everything I have read says to use scan.usedelimiter(","); but everywhere I try to use it the program throws straight to the catch that replies "Error converting number". If anyone can help I would greatly appreciate it. I also saw some information about using split for the buffered reader, but I don't know which would be better to use/why/how.</p>
  
  <pre><code>    String filename = "res/test.txt"; // Finds the file you want to test.
  
  
      try{
          FileReader ConnectionToFile = new FileReader(filename);
          BufferedReader read = new BufferedReader(ConnectionToFile);
          Scanner scan = new Scanner(read);
  
          int[][] Spaces = new int[10][10];
          int counter = 0;
          try{
              while(scan.hasNext() &amp;&amp; counter &lt; 10)
              {
                  for(int i = 0; i &lt; 10; i++)
                  {
                      counter = counter + 1;
                      for(int m = 0; m &lt; 10; m++)
                      {
                          Spaces[i][m] = scan.nextInt();
                      }
                  }
              }
              for(int i = 0; i &lt; 10; i++)
              {
                  //Prints out Arrays to the Console, (not needed in final)
                  System.out.println("Array" + (i + 1) + " is: " + Spaces[i][0] + ", " + Spaces[i][1] + ", " + Spaces[i][2] + ", " + Spaces[i][3] + ", " + Spaces[i][4] + ", " + Spaces[i][5] + ", " + Spaces[i][6]+ ", " + Spaces[i][7]+ ", " + Spaces[i][8]+ ", " + Spaces[i][9]);
              }
          } 
          catch(InputMismatchException e)
          {
              System.out.println("Error converting number");
          }
          scan.close();
          read.close();
      }
      catch (IOException e)
      {
      System.out.println("IO-Error open/close of file" + filename);
      }
  }
  </code></pre>