一、檔案轉位元組流
//利用FileStream讀取檔案
//FileStream fs = System.IO.File.OpenRead(name);
FileStream fs = new FileStream(filename,FileMode.Open, FileAccess.Read);
//定義位元組流
byte[] bytes = new byte[fs.Length];
//檔案讀取到位元組流中
fs.Read(bytes, 0, bytes.Length);
//關閉讀取
fs.Close();
二、位元組流轉檔案
//定義檔案名稱 路徑加檔案名稱
string filename="D:\hello.jpg";
//建立一個檔案流
FileStream fs = new FileStream("D:\inf.dlv",FileMode.Create, FileAccess.Write);
//把位元組寫入到檔案流中
fs.Write(infbytes, 0, inf.Length);
//關閉檔案流