@Test public void testLoadSerializedData() { try { System.out.println("loadSerializedData"); String filename = "unitTestSerializedData"; Hashtable<String, Integer> data = (Hashtable<String, Integer>) SimpleIO.loadSerializedData(filename); assertNotNull(data); System.out.println(data); assertEquals(2, data.size()); assertEquals(3, data.get("foo").intValue()); } catch (FileNotFoundException ex) { ex.printStackTrace(); fail("testSaveSerializedData() test failed, as this test cannot load it's testdata.."); } }
public static Object loadSerializedData(String filename) throws FileNotFoundException { FileInputStream fis; ObjectInputStream ois; Object data; try { File file = new File(filename); if (!file.exists()) { return null; } fis = new FileInputStream(file); ois = new ObjectInputStream(fis); data = (Object) ois.readObject(); ois.close(); fis.close(); return data; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { ois = null; fis = null; } return null; }
SimpleIO { public static Object loadSerializedData(String filename) throws FileNotFoundException { FileInputStream fis; ObjectInputStream ois; Object data; try { File file = new File(filename); if (!file.exists()) { return null; } fis = new FileInputStream(file); ois = new ObjectInputStream(fis); data = (Object) ois.readObject(); ois.close(); fis.close(); return data; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { ois = null; fis = null; } return null; } }
SimpleIO { public static Object loadSerializedData(String filename) throws FileNotFoundException { FileInputStream fis; ObjectInputStream ois; Object data; try { File file = new File(filename); if (!file.exists()) { return null; } fis = new FileInputStream(file); ois = new ObjectInputStream(fis); data = (Object) ois.readObject(); ois.close(); fis.close(); return data; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { ois = null; fis = null; } return null; }  }
SimpleIO { public static Object loadSerializedData(String filename) throws FileNotFoundException { FileInputStream fis; ObjectInputStream ois; Object data; try { File file = new File(filename); if (!file.exists()) { return null; } fis = new FileInputStream(file); ois = new ObjectInputStream(fis); data = (Object) ois.readObject(); ois.close(); fis.close(); return data; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { ois = null; fis = null; } return null; }  static void createFolder(String foldername); static void createFile(String filename); static void writelineToFile(String filename, String line); static void writeToFile(String filename, String line); static void appendLinesToFile(String filename, List<String> lines); static void appendLineToFile(String filename, String line); static void appendToFile(String filename, String line); static String readFileAsString(String filename); static ArrayList<String> readFileAsList(String filename); static Map<String, String> loadConfig(String filename); static void saveConfig(String filename, Map<String, String> config); static boolean saveSerializedData(String filename, Object data); static Object loadSerializedData(String filename); }
SimpleIO { public static Object loadSerializedData(String filename) throws FileNotFoundException { FileInputStream fis; ObjectInputStream ois; Object data; try { File file = new File(filename); if (!file.exists()) { return null; } fis = new FileInputStream(file); ois = new ObjectInputStream(fis); data = (Object) ois.readObject(); ois.close(); fis.close(); return data; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { ois = null; fis = null; } return null; }  static void createFolder(String foldername); static void createFile(String filename); static void writelineToFile(String filename, String line); static void writeToFile(String filename, String line); static void appendLinesToFile(String filename, List<String> lines); static void appendLineToFile(String filename, String line); static void appendToFile(String filename, String line); static String readFileAsString(String filename); static ArrayList<String> readFileAsList(String filename); static Map<String, String> loadConfig(String filename); static void saveConfig(String filename, Map<String, String> config); static boolean saveSerializedData(String filename, Object data); static Object loadSerializedData(String filename);  }