1 public static String ToXmlText(Object obj)throws Exception { 2 ByteArrayOutputStream bos= new ByteArrayOutputStream(); 3 XMLEncoder encoder = new XMLEncoder(bos); 4 encoder.writeObject(obj); 5 encoder.flush(); 6 encoder.close(); 7 return new String(bos.toByteArray(),"UTF-8"); 8 }
解码时,
1 XMLDecoder d = new XMLDecoder( 2 new ByteArrayInputStream(ss.getBytes("UTF-8"))); 3 obj = d.readObject(); 4 d.close();
时间: 2024-12-29 15:38:15