java 负责对象序列化
补充:public String getUsersToString() {
String strResult = "";
HashMap myHM = new HashMap();
List<User> myAL = new ArrayList<User>();
User user = new User();
user.setLoginName("jilei");
user.setPassword("123456");
myAL.add(user);
User user2 = new User();
user2.setLoginName("jilei2");
user2.setPassword("1234562");
myAL.add(user2);
myHM.put("myAL", myAL);
//序列化使用的输出流
ObjectOutputStream OOS = null;
ByteArrayOutputStream BAOS = new ByteArrayOutputStream();
try {
OOS = new ObjectOutputStream(BAOS);
OOS.writeObject(myHM);//运行到这,报错
byte[] buff = BAOS.toByteArray();
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
strResult = encoder.encode(buff);
OOS.close();
} catch (Exception ex) {
System.out.println("序列化时产生错误 ");
ex.printStackTrace();
}
System.out.println("before return strResult=====\n" + strResult);
System.out.println("end");
return strResult;
}