code: static int readInt(String location) throws IOException {
          BufferedReader r = new BufferedReader(new FileReader(location));
          String s = r.readLine();
          r.close();
          try {
              if (s != null && s.length() > 0) {
                  return Integer.parseInt(s);
              } else {
                  throw new IOException(location + " does not contain an integer");
              }
          } catch (NumberFormatException e) {
              throw new IOException(
                      location + " does not contain an integer ('" + s + "'");
          }
      }
docs: Read a single integer value from a file