如何生成**.dat文件,记事本能打开,不要求加密

解决方案 »

  1.   

    直接指定xxx.dat文件名就可以了。
    其实文件扩展名和文件的内容是无关的。
      

  2.   

    public class Person
        {
            public Person()
            {
            }
            
            public int Age;
            //[NonSerialized]
            public int Money;
            
            public void creat()
            {
                Person me = new Person();
                me.Age = 34;
                me.Money = 200;
                Stream s = File.Open("Me.dat", FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(s, me);
                s.Close();
            }
            public void open() {
                Stream s = File.Open("Me.dat", FileMode.Open);
                BinaryFormatter bf = new BinaryFormatter();
                object o = bf.Deserialize(s);  
                Person p = o as Person;
                if (p != null)
                    Console.WriteLine("Person 年龄:{0} 钱:{1}", p.Age, p.Money);
                Console.Read();
                s.Close();
            }
            static void Main(string[] args)
            {
                Person ps = new Person();
                ps.creat();
                ps.open();   
            }
        }//这个是我在做别的例子,不过也可以用,里面有如何创建,如何打开,你可以用看看
      

  3.   

    dat只是个后缀而已,随便一在里面写什么