1. 程式人生 > >C# 檔案和位元組流的轉換

C# 檔案和位元組流的轉換

1、讀取檔案,並轉換為位元組流 FileStream fs = new FileStream(filename,FileMode.Open, FileAccess.Read); 
byte[] infbytes = new byte[(int)fs.Length]; 
fs.Read(infbytes, 0, infbytes.Length); 
fs.Close(); 
return infbytes;


2、將位元組流寫入檔案 FileStream fs = new FileStream("D:\inf.dlv",FileMode.Create, FileAccess.Write); 
fs.Write(infbytes, 0, inf.Length); 

fs.Close();