我在j2me中开发了一个应用程序,它具有用户定义类对象的蓝牙通信功能。 我使用以下代码收到了字节数组:
public byte[] receiveBoard() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ins = conn.openInputStream();
int n;
while((n=ins.read(brd))>0) {
baos.write(brd, 0, n);
}
} catch(Exception e) {
System.err.println(e);
}
return baos.toByteArray();
}
现在我的问题是,
我尝试使用ObjectInputStream,ObjectInput类,但它没有导入这些包! 请快点帮帮我!!!!
答案 0 :(得分:1)
不,它不起作用,您必须在J2ME中进行自己的对象序列化。这意味着要确定要序列化的对象的哪些属性,并编写自己的代码将对象写入字节数组,然后再将其读回。
您可能会发现DataInputStream
和DataOutputStream
对此非常有用。