code: static int[] readInts(String location, int expectedLength) throws IOException {
          BufferedReader r = new BufferedReader(new FileReader(location));
          String s = r.readLine();
          r.close();
          if (s != null && s.length() > 0) {
              String[] elements = s.split(",");
              try {
                  if (expectedLength == 0 || elements.length == expectedLength) {
                      int[] xs = new int[elements.length];
                      for (int i = 0; i < xs.length; i++) {
                          xs[i] = Integer.parseInt(elements[i]);
                      }
                      return xs;
                  }
              } catch (NumberFormatException e) {
                  // fall through to throw an IOException
              }
          }
          if (expectedLength != 0) {
              throw new IOException("Expected to find " + expectedLength
                      + " integers in " + location + " but found '"
                      + s + "'");
          } else {
              return new int[0];
          }
      }
docs: Read a comma-separated list of integer values from a file