import java.io.*; public class GraphDataObjectReader { private GraphWithMapData data; private String filename; public GraphDataObjectReader(String filename, boolean verbose) throws IOException { if(!filename.matches(".*\\.ser")){ filename = filename + ".ser"; } this.filename = filename; try(//don't need to close these because of try-with-resources BufferedInputStream fileIn = new BufferedInputStream(new FileInputStream(filename)); ObjectInputStream in = new ObjectInputStream(fileIn)) { if (verbose) { System.out.println("Reading graph data from file. This may take some time"); System.out.println("File I/O time is not included in results"); } data = (GraphWithMapData) in.readObject(); } catch (FileNotFoundException | ClassNotFoundException ex) { System.out.println("Graph/data file " + filename + " not found."); ex.printStackTrace(); } } public GraphWithMapData getData() { return data; } public String getFilename() { return filename; } }