public static void Write() { Person1 pe = new Person1() { userName = "******", securityNumber = "123Bansal", age = 23 }; Stream fs = new FileStream("bal.txt", FileMode.Create, FileAccess.Write, FileShare.None); IFormatter f = new BinaryFormatter(); f.Serialize(fs, pe); fs.Close(); }
public static void Read() { BasicConfigurator.Configure(); Person1 ps = new Person1(); BinaryFormatter bf = new BinaryFormatter(); Stream fs = new FileStream("bal.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.Read); Person1 pe = (Person1)bf.Deserialize(fs); fs.Close(); log.Info("Username : "******"SecurityInformation : " + ps.securityNumber); log.Info("age : " + ps.age); Console.WriteLine("Go to Logger ...............Loding"); }