c# 클래스 파일로 저장
Bit/C# / 2012. 2. 3. 21:22
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
namespace classsave
{
class Program
{
static void Main(string[] args)
{
Human h = new Human("dd","111","1123");
BinaryFormatter format = new BinaryFormatter();
try
{
Stream s = File.Open("c:\\human.txt", FileMode.Create, FileAccess.ReadWrite);
format.Serialize(s, h);
s.Close();
s = File.Open("c:\\human.txt", FileMode.Open, FileAccess.Read);
Object o = format.Deserialize(s);
Human r = (Human)o;
r.Print();
}
catch (IOException e)
{
Console.WriteLine(e.Message);
}
catch (SerializationException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
namespace classsave
{
class Program
{
static void Main(string[] args)
{
Human h = new Human("dd","111","1123");
BinaryFormatter format = new BinaryFormatter();
try
{
Stream s = File.Open("c:\\human.txt", FileMode.Create, FileAccess.ReadWrite);
format.Serialize(s, h);
s.Close();
s = File.Open("c:\\human.txt", FileMode.Open, FileAccess.Read);
Object o = format.Deserialize(s);
Human r = (Human)o;
r.Print();
}
catch (IOException e)
{
Console.WriteLine(e.Message);
}
catch (SerializationException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}