用StreamReader 和StreamWriter 类读写字符串

读写字符串可以用StreamReader 和StreamWriter 类。写字符串类型数据代码段如下: System.IO.FileStream fs=new System.IO.FileStream("g1",FileMode.OpenOrCreate); System.IO.StreamWrite w=new System.IO.StreamWrite(fs); w.Write(100); w.Write("100 个"); w.Write("End of file"); w.Close(); 读字符串代码段如下: String[] data=new String[3]; System.IO.FileStream fs=new System.IO.FileStream("g1",FileMode.OpenOrCreate); System.IO.StreamReader r=new System.IO.StreamReader(fs); For(int i=0;i<3;i++) data[i]=r.ReadLine(); r.Close();

你可能感兴趣的:(用StreamReader 和StreamWriter 类读写字符串)