//獲得當(dāng)前文件目錄
string rootPath = Directory.GetCurrentDirectory();
string path = rootPath + "Your File Path";
FileStream stream = new FileStream(path, FileMode.Open);
//Position應(yīng)該被重置為0印蔬,否則讀取的時(shí)候會(huì)從最后開始讀分冈,讀不出來┭┮﹏┭┮
stream.Position = 0;
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
byte[] bytes = ms.ToArray();
string rootPath = Directory.GetCurrentDirectory();
string path = rootPath + "Your File Path";
FileStream stream = new FileStream(path, FileMode.Open);
stream.Position = 0;
byte[] bytes = new byte[stream.Length];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = stream.Read(bytes, 0, bytes.Length)) > 0)
{
ms.Write(bytes, 0, read);
}
bytes = ms.ToArray();
}