@Test public void testSaveSerializedData() { System.out.println("saveSerializedData"); String filename = "unitTestSerializedData"; Hashtable<String, Integer> data = new Hashtable<String, Integer>(); data.put("foo", 3); data.put("bar", 2); boolean result = SimpleIO.saveSerializedData(filename, data); assertTrue(result); }
public static boolean saveSerializedData(String filename, Object data) { FileOutputStream fosStream; ObjectOutputStream outStream; try { File file = new File(filename); file.delete(); file.createNewFile(); fosStream = new FileOutputStream(file); outStream = new ObjectOutputStream(fosStream); outStream.writeObject(data); outStream.flush(); outStream.close(); return true; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { outStream = null; fosStream = null; } return false; }
SimpleIO { public static boolean saveSerializedData(String filename, Object data) { FileOutputStream fosStream; ObjectOutputStream outStream; try { File file = new File(filename); file.delete(); file.createNewFile(); fosStream = new FileOutputStream(file); outStream = new ObjectOutputStream(fosStream); outStream.writeObject(data); outStream.flush(); outStream.close(); return true; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { outStream = null; fosStream = null; } return false; } }
SimpleIO { public static boolean saveSerializedData(String filename, Object data) { FileOutputStream fosStream; ObjectOutputStream outStream; try { File file = new File(filename); file.delete(); file.createNewFile(); fosStream = new FileOutputStream(file); outStream = new ObjectOutputStream(fosStream); outStream.writeObject(data); outStream.flush(); outStream.close(); return true; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { outStream = null; fosStream = null; } return false; }  }
SimpleIO { public static boolean saveSerializedData(String filename, Object data) { FileOutputStream fosStream; ObjectOutputStream outStream; try { File file = new File(filename); file.delete(); file.createNewFile(); fosStream = new FileOutputStream(file); outStream = new ObjectOutputStream(fosStream); outStream.writeObject(data); outStream.flush(); outStream.close(); return true; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { outStream = null; fosStream = null; } return false; }  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 boolean saveSerializedData(String filename, Object data) { FileOutputStream fosStream; ObjectOutputStream outStream; try { File file = new File(filename); file.delete(); file.createNewFile(); fosStream = new FileOutputStream(file); outStream = new ObjectOutputStream(fosStream); outStream.writeObject(data); outStream.flush(); outStream.close(); return true; } catch (IOException ex) { Logger.getLogger(SimpleIO.class.getName()).log(Level.SEVERE, null, ex); } finally { outStream = null; fosStream = null; } return false; }  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);  }