序列化
序列化在.net中用的很多,webservice,viewstate等都有涉及
三种序列化方式:soap,xml,2进制
soap,2进制: 深度序列化(public,private等全部序列化),生成soap消息
xml: 非深度序列化(只序列化public),生成xml文件
序列化:
class SerializeExample{
public static void Main(String[] args)
{
l = new ArrayList(); for (int x=0; x< 100; x++)
{ l.Add (x); }
FileStream s = File.Create("foo.bin");
b = new BinaryFormatter();
b.Serialize(s, l);
s.Close(); } }
反序列化:
class DeSerialize {
public static void Main(String[] args)
{
s = File.OpenRead("foo.bin");
BinaryFormatter b = new BinaryFormatter();
ArrayList p = (ArrayList) b.Deserialize(s); s.Close();
}
src:http://www.cnblogs.com/.net%20lover/archive/2004/09/23/46045.aspx
posted on 2004-09-24 08:41 HelloSnoopy 阅读(529) 评论(0) 编辑 收藏 举报