public void writeToFile(String filename) throws IOException {
    File file = new File(filename);
    file.mkdirs();
    PrintWriter out = new PrintWriter(new FileWriter(file));

    out.println(name);
    out.println(size);

    for (int x = 0; x < size; x++) {
      out.println(vertices.get(x));
    }

    for (int x = 0; x < size; x++) {
      StringBuffer buf = new StringBuffer();
      for (int e : outedges[x]) {
        buf.append(e);
        buf.append(" ");
      }
      out.println(buf.toString().trim());
    }

    out.flush();
    out.close();
  }