.NET ez 2011-11-29
.NET Framework提供了BinaryReader與BinaryWriter用來處理二進位資料
讀取
FileStream myFile = File.Open(@"C:\a.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); BinaryReader myReader = new BinaryReader(myFile); int dl = Convert.ToInt32(myFile.Length); byte[] myData = myReader.ReadBytes(dl); myReader.Close(); myFile.Close();
寫入
FileStream myFile = File.Open(@"C:\a.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); BinaryWriter myWriter = new BinaryWriter(myFile); byte[] myByte = new byte[] { 1, 2, 3, 4, 5, 6 }; myWriter.Write(myByte); myWriter.Close(); myFile.Close();
標籤: .NET
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-File-BinaryReader-BinaryWriter
https://www.ez2o.com/Blog/Post/12
https://www.ez2o.com/Blog/Post/csharp-File-BinaryReader-BinaryWriter
https://www.ez2o.com/Blog/Post/12