Skip to content

Instantly share code, notes, and snippets.

@tckb
Last active December 31, 2015 20:38
Show Gist options
  • Save tckb/8041061 to your computer and use it in GitHub Desktop.
Save tckb/8041061 to your computer and use it in GitHub Desktop.
Code fragment
// Code part of tckb-lib
// Author: tckb <[email protected]>
// https://github.com/tckb/jAudIO.pub
public static void saveObjectToFile(File thatFile, Object... thisObject) {
mylogger.log(Level.INFO, "Saving object{0} to file: {1}", new Object[]{thisObject.hashCode(), thatFile.getAbsolutePath()});
ObjectOutputStream stream;
try {
stream = new ObjectOutputStream(new FileOutputStream(thatFile));
stream.writeObject(thisObject);
stream.close();
} catch (IOException ex) {
mylogger.log(Level.SEVERE, "Error: Can not save the object!", ex.getMessage());
}
}
public static Object[] getObjectFromFile(File thatFile) {
mylogger.log(Level.INFO, "Extracting object from file: {0}", thatFile.getAbsolutePath());
Object[] thatObject = null;
try {
ObjectInputStream stream = new ObjectInputStream(new FileInputStream(thatFile));
thatObject = (Object[]) stream.readObject();
stream.close();
} catch (Exception ex) {
mylogger.log(Level.SEVERE, "Error: Can not extract the object from file", ex.getMessage());
}
return thatObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment