标签:
class Program { static void Main(string[] args) { //FileStream 写入文件 //FileMode.Create 新内容覆盖老内容 using (FileStream fs = new FileStream(@"C:\Users\Administrator\Desktop\C#OOP练习\my.txt",FileMode.Create)) { byte[] bytes = Encoding.Default.GetBytes("你好,如鹏网"); fs.Write(bytes, 0, bytes.Length); } //FileStream 读取文件 using (FileStream fs = new FileStream(@"C:\Users\Administrator\Desktop\C#OOP练习\my.txt",FileMode.Open)) { byte[] bytes = new byte[4]; int length; while ((length = fs.Read(bytes, 0, bytes.Length)) > 0) { string s = Encoding.Default.GetString(bytes, 0, length); Console.WriteLine(s); } } Console.ReadKey(); } }
标签:
原文地址:http://www.cnblogs.com/phpweige/p/4774125.html