如何将输入流转换为java对象
发布时间:2020-05-25 15:03:23 所属栏目:Java 来源:互联网
导读:ByteArrayOutputStream baos = new ByteArrayOutputStream();ObjectOutputStream oos = new ObjectOutputStream(baos);oos.writeObject(reg_be);oos.flush();oos.close();InputStream is = new ByteArrayInput
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(reg_be); oos.flush(); oos.close(); InputStream is = new ByteArrayInputStream(baos.toByteArray()); 此代码将Java Object转换为InputStream,如何将InputStream转换为Object?我需要将我的对象转换为InputStream然后我传递它,我想让我的对象回来. 解决方法在try块中你应该写:ObjectInputStream ois = new ObjectInputStream(is); Object object = ois.readObject(); ObjectInputStream用另一个流初始化,例如BufferedInputStream或您的输入流是. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
