天使半只翼

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
         if (Directory.Exists(Server.MapPath("~/upimg/hufu")) == false)//如果不存在就创建file文件夹
         {
             Directory.CreateDirectory(Server.MapPath("~/upimg/hufu"));
         }

 

public void SerializeNow()
    {
        ClassToSerialize c = new ClassToSerialize();
        FileStream fileStream = new FileStream("c:\\temp.dat", FileMode.Create);
        BinaryFormatter b = new BinaryFormatter();
        b.Serialize(fileStream, c);
        fileStream.Close();
    }
    public void DeSerializeNow()
    {
        ClassToSerialize c = new ClassToSerialize();
        c.Sex = "kkkk";
        FileStream fileStream = new FileStream("c:\\temp.dat", FileMode.Open, FileAccess.Read, FileShare.Read);
        BinaryFormatter b = new BinaryFormatter();
        c = b.Deserialize(fileStream) as ClassToSerialize;
          Response.Write(c.name);
        Response.Write(c.Sex);
        fileStream.Close();
    }

 

try
   {
    FileStream aFile = new FileStream(@"c:\祝福.txt", FileMode.Open);
    StreamReader sr = new StreamReader(aFile);
    string strLine = sr.ReadLine();
    while(strLine != null)
    {
     Console.WriteLine(strLine);
     strLine = sr.ReadLine();
    }
    sr.Close();
   }
   catch (IOException ex)
   {
    Console.WriteLine(ex.Message);
    Console.ReadLine();
    return ;
   }

 

posted on 2013-01-21 00:29  天使半只翼  阅读(370)  评论(0编辑  收藏  举报