public void loadFromFile(File positionFile) throws java.io.IOException { logger.logComment("Loading position records from file: " + positionFile.getAbsolutePath()); this.reset(); Reader in = new FileReader(positionFile); LineNumberReader reader = new LineNumberReader(in); String nextLine = null; String currentInputRef = null; while ((nextLine = reader.readLine()) != null) { // logger.logComment("Parsing line: "+ nextLine); if (nextLine.endsWith(":")) { currentInputRef = nextLine.substring(0, nextLine.length() - 1); logger.logComment("currentInputRef: " + currentInputRef); } else { SingleElectricalInput input = new SingleElectricalInput(nextLine); this.addSingleInput(currentInputRef, input); } } in.close(); logger.logComment("Finished loading cell info. Internal state: " + this.toString()); }
public void saveToFile(File inputsFile) throws java.io.IOException { logger.logComment( "Saving " + this.getNumberSingleInputs() + " inputs to file: " + inputsFile.getAbsolutePath()); // will create the parent dir if it doesn't exist. if (!inputsFile.exists()) { logger.logComment("File: " + inputsFile + " doesn't exist."); if (!inputsFile.getParentFile().exists()) { logger.logComment("Parent dir: " + inputsFile.getParentFile() + " doesn't exist."); // String parentDirName = inputsFile.getParentFile().getCanonicalPath(); File projectDir = inputsFile.getParentFile().getParentFile(); if (!projectDir.exists()) { throw new FileNotFoundException( "Project dir doesn't exist: " + projectDir.getAbsolutePath()); } // logger.logComment("Going to create dir: "+ parentDirName +" in dir :"+ projectDir); logger.logComment("Going to create dir: " + inputsFile.getParentFile()); inputsFile.getParentFile().mkdir(); logger.logComment("Success? " + inputsFile.getParentFile().exists()); } } FileWriter fw = new FileWriter(inputsFile); Enumeration keys = this.myElecInputs.keys(); while (keys.hasMoreElements()) { String input = (String) keys.nextElement(); ArrayList<SingleElectricalInput> inputs = getInputLocations(input); fw.write(input + ":\n"); for (int i = 0; i < inputs.size(); i++) { fw.write(inputs.get(i) + "\n"); } } logger.logComment("Finished saving data to file: " + inputsFile.getAbsolutePath()); fw.flush(); fw.close(); }