public static void convertObjectToFile(Object obj, String filename) {
	Ts.convertByteArrayToFile(Ts.convertObjectToByteArray(obj), filename);
}
 
public static void convertByteArrayToFile(byte[] stream, String filename) {
	java.io.File f = new java.io.File(filename);
	java.io.FileOutputStream fos = null;
	try {
		fos = new java.io.FileOutputStream(f);
	} catch (java.io.FileNotFoundException ex) {
		Ts.printErr(ex);
	}
	try {
		fos.write(stream);
		fos.close();
	} catch (java.io.IOException ex) {
		Ts.printErr(ex);
	}
}
 
public static byte[] convertObjectToByteArray(Object obj) {
	java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
	java.io.ObjectOutputStream oos = null;
	try {
		oos = new java.io.ObjectOutputStream(baos);
		oos.writeObject(obj);
		oos.flush();
		oos.close();
	} catch (java.io.IOException ex) {
		Ts.printErr(ex);
	}
	return baos.toByteArray();
}
 
public static void printErr(java.lang.Exception ex) {
	printErr(ex.getMessage());
}


Back to JavaHowTo

Alumni Liaison

Ph.D. on Applied Mathematics in Aug 2007. Involved on applications of image super-resolution to electron microscopy

Francisco Blanco-Silva