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 ; }