title: java initialize object from file
body: <p>I am currently writing a program that deals with graphs created by the jgrapht library. I have multiple graphs of the form:</p>
  
  <pre><code>UndirectedGraph &lt;Integer, DefaultEdge&gt; g_x = new SimpleGraph&lt;Integer, DefaultEdge (DefaultEdge.class);
  g.addVertex(1);
  g.addVertex(2);
  g.addVertex(3);
  g.addEdge(1, 2);
  g.addEdge(2, 4);
  ...
  </code></pre>
  
  <p>which are constant graphs associated with street maps that I am given as files. Right now I have all of my graphs declared in my main method and just reference the graph I want when a map is loaded. What I would like to do is have another file paired with each map (i.e map1.map and map1.graph) so that when I load the map from a file I can also load the graph like:</p>
  
  <pre><code>map = loadMap(mapName);
  g_x = loadGraph(mapName);
  </code></pre>
  
  <p>where mapName is the file name prefix and not have to store it in my source code. Is it possible to do this in java and if so how would I create the files and load them? Would it also be possible to do this with a generic Object?</p>