c# 文件流读写信息

来源:互联网 发布:vscode支持xp吗 编辑:程序博客网 时间:2024/06/06 02:32
            string msg = "dhgfjdbghafj";            byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg);            //向流中写入信息            using (FileStream fsWrite = new FileStream(@"D:111.txt", FileMode.OpenOrCreate, FileAccess.Write))            {                fsWrite.Write(myByte,0,myByte.Length);            }            //读文件            using (FileStream fsRead = new FileStream(@"D:111.txt", FileMode.OpenOrCreate, FileAccess.Read))            {                int mylength = (int)fsRead.Length;                byte[] heByte = new byte[mylength];                int r = fsRead.Read(heByte,0,heByte.Length);                string myStr = System.Text.Encoding.UTF8.GetString(heByte);                Console.Write(myStr);                Console.ReadKey();            }
                                             
1 0
原创粉丝点击