title: Reading from a file a line that has commas and spaces in java
body: <p>I'm reading from a file that has a line which has a pair of number separated by commas:</p>
  
  <pre><code>1 2, 2 3, 3 1, 4 1, 2 4, S
  </code></pre>
  
  <p>With the result being:</p>
  
  <pre><code>ValueOne - 1 -- ValueTwo - 2 
  ValueOne - 2 -- ValueTwo - 3 
  ValueOne - 3 -- ValueTwo - 1 
  ValueOne - 4 -- ValueTwo - 1
  ValueOne - 2 -- ValueTwo - 4
  Break
  </code></pre>
  
  <p>This is my current code:</p>
  
  <pre><code>try{
          Scanner scanner = new Scanner(new File("graph.txt"));
          while(scanner.hasNextLine()){
              String value = scanner.next();
              String[] values = value.split(" |,");
              if(value.equals("S")){
                  System.out.println("Break");
                  break;
              }
              int v1 = Integer.parseInt(values[0]);
              int v2 = Integer.parseInt(values[1]);
              System.out.println("ValueOne - " + v1 + " -- " + "ValueTwo - "+ v2);
          }
          scanner.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I'm getting an <strong>ArrayIndexOutOFBoundsException</strong> at "int v2 = Integer.parseInt(values[1]);"</p>
  
  <p>I'm sure I'm missing something silly, but I just need some fresh eyes to take a look at it. Thanks.</p>