Java Object to Byte Array getBytes(Object obj)

Here you can find the source of getBytes(Object obj)

Description

get Bytes

License

Open Source License

Declaration

private static byte[] getBytes(Object obj) throws java.io.IOException 

Method Source Code


//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.ObjectOutputStream;

public class Main {
    private static byte[] getBytes(Object obj) throws java.io.IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(obj);/*from   w  w  w  . j a  va2s . co m*/
        oos.flush();
        oos.close();
        bos.close();
        byte[] data = bos.toByteArray();
        return data;
    }
}

Related

  1. getBytes(Object o)
  2. getBytes(Object o)
  3. getBytes(Object o)
  4. getBytes(Object obj)
  5. getBytes(Object obj)
  6. getBytes(Object obj)
  7. getBytes(Object obj)
  8. getBytes(Object obj)