Java - general

object to byte-array

The conversion of any object to a byte-array can be carried out as follows:

public byte[] getBytes(Object obj) throws java.io.IOException{
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutputStream oos = new ObjectOutputStream(baos);
   oos.writeObject(obj);
   oos.flush();
   oos.close();
   baos.close();
   byte [] ba = baos.toByteArray();
   return ba;
}


See also byte-array to object


Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007