本文共 906 字,大约阅读时间需要 3 分钟。
-
- public static String writeObject(Object o) throws Exception {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos);
- oos.writeObject(o);
- oos.flush();
- oos.close();
- bos.close();
-
- return new String(bos.toByteArray(), "ISO-8859-1");
- }
-
-
-
- public static Object readObject(String object) throws Exception{
-
- ByteArrayInputStream bis = new ByteArrayInputStream(object.getBytes("ISO-8859-1"));
- ObjectInputStream ois = new ObjectInputStream(bis);
- Object o = null;
- try {
- o = ois.readObject();
- } catch(EOFException e) {
- System.err.print("read finished");
- }
- bis.close();
- ois.close();
- return o;
- }
转载于:https://blog.51cto.com/daheyuan/1140904