How to serialize ByteBuffer
问题 I wish to send a java.nio.ByteBuffer accross a network using RMI, however ByteBuffer isn't serializable. I've tried the following custom class to no avail: public class NetByteBuffer implements java.io.Serializable { ByteBuffer buffer; public NetByteBuffer(ByteBuffer buffer) { this.buffer = buffer; } public ByteBuffer getByteBuffer() { return this.buffer; } } The client still gets a non-serialzable exception. Any ideas? Thanks 回答1: You can't. You'd better obtain the byte[] and send it instead