using System.IO;//必须包含此命令空间
static void Main(string[] args) { byte[] byteFile = new byte[30]; char[] charFile = new char[30]; string path = @"D:\TEST.txt"; FileStream fe = new FileStream(path,FileMode.OpenOrCreate,FileAccess.ReadWrite);//实例化FileStream fe.Seek(0,SeekOrigin.Begin); fe.Read(byteFile,0, byteFile.Length);//读取TXT文件 Decoder dc = Encoding.Default.GetDecoder(); dc.GetChars(byteFile,0, byteFile.Length,charFile,0,true); Console.WriteLine(charFile); charFile = "世界人民大团结万岁~!".ToCharArray();//写入数字串。 Encoder en = Encoding.Default.GetEncoder(); en.GetBytes(charFile, 0, charFile.Length, byteFile, 0, true); fe.Seek(0, SeekOrigin.Begin); fe.Write(byteFile, 0, byteFile.Length); Console.ReadKey(); }
浙公网安备 33010602011771号