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();

  

3.將字節流轉換成文件流
Stream stream = new MemoryStream(bytes); 
return stream; 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM