java 字符串系列化及反系列化
2018-07-20 来源:open-open
/**
* 字符串序列化
* @param str
* @return
*/
public static String compareSerialization(String str) {
String result = "";
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(str);
result = byteArrayOutputStream.toString("ISO-8859-1");
result = java.net.URLEncoder.encode(result, "UTF-8");
objectOutputStream.close();
byteArrayOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 字符串反序列化
* @param serStr
* @return
*/
public static String deSerialization(String serStr) {
String result = "";
try {
result = java.net.URLDecoder.decode(serStr, "UTF-8");
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result.getBytes("ISO-8859-1"));
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
result = (String) objectInputStream.readObject();
objectInputStream.close();
byteArrayInputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
return result;
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐