private void loadChains() throws IOException, ClassNotFoundException { File file = new File("./Markov/Markov.Chains"); if (!file.exists()) { logger.log( "Markov.Chains does not exist @: " + file.getPath() + " Please Call SaveChains to Create it" + "."); } else { try (FileInputStream fis = new FileInputStream(file); ObjectInputStream chainLoader = new ObjectInputStream(new BufferedInputStream(fis))) { chains = (HashMap<String, HashMap<String, Integer>>) chainLoader.readObject(); logger.log("Chains Loaded Successfully from: " + file.getPath()); } } }
public synchronized boolean saveChains() throws IOException { boolean success = false; File file = new File("./Markov"); if (!file.exists()) { logger.log("Markov Directory does Not Exist. Creating! " + file.mkdirs()); } else { try (FileOutputStream fos = new FileOutputStream(file + "/Markov.Chains"); ObjectOutputStream chainSaver = new ObjectOutputStream(fos)) { logger.log("Saving Chains to: " + file + "Markov.Chains"); chainSaver.writeObject(chains); logger.log("Success!"); success = true; } } return success; }