文件和字節流的相互轉換

一、讀取文件,並轉換爲字節流 
spa

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;

 

 


 二、將字節流寫入文件 
code

FileStream fs = new FileStream("D:\inf.dlv", FileMode.Create, FileAccess.Write);
            fs.Write(inf, 0, inf.Length);
            fs.Close();
相關文章
相關標籤/搜索