C# – 如何读写二进制文件?
发布时间:2020-12-15 04:03:29 所属栏目:百科 来源:网络整理
导读:如何从任何文件读取原始字节数组,并将该字节数组写回新文件? 解决方法 (编辑:注意问题改变了,最初没有提到byte [];见 revision 1) 嗯,File.Copy跳跃了起来;但是否则这听起来像一个Stream场景: using (Stream source = File.OpenRead(inPath)) using (Stre
如何从任何文件读取原始字节数组,并将该字节数组写回新文件?
解决方法
(编辑:注意问题改变了,最初没有提到byte [];见
revision 1)
嗯,File.Copy跳跃了起来;但是否则这听起来像一个Stream场景: using (Stream source = File.OpenRead(inPath)) using (Stream dest = File.Create(outPath)) { byte[] buffer = new byte[2048]; // pick size int bytesRead; while((bytesRead = source.Read(buffer,buffer.Length)) > 0) { dest.Write(buffer,bytesRead); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |