2012-02-13 35 views

Trả lời

40

Bạn có thể sử dụng ObjectOutputStream

Bạn viết các đối tượng (obj trong mã bên dưới) sang ObjectOutputStream, đối tượng mà bạn muốn chuyển đổi sang một input stream phải thực hiện Serializable.


ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    ObjectOutputStream oos = new ObjectOutputStream(baos); 


    oos.writeObject(obj); 

    oos.flush(); 
    oos.close(); 

    InputStream is = new ByteArrayInputStream(baos.toByteArray()); 
+0

nó một thử nghiệm tốt đẹp, nhưng không phải là rất thuận tiện để lưu/khôi phục jpeg. – taitelman

+0

nếu obj không triển khai giao diện Serializable. – PeaceIsPearl

Các vấn đề liên quan