解决:
File.WriteAllBytes
http://msdn.microsoft.com/zh-cn/library/system.io.file.writeallbytes.aspx
其他:
这里要注意,byte[]数组里面可能有不可见字符,所以程序里不要进行如GetString()之类的转换,这样会出错的,对一些不可见的字符会有乱码。可以用写二进制流的方式进行读写文件即可。
FileStream fs1 = new FileStream(@"E:\tenp\doc\111.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fs2 = new FileStream(@"E:\temp\doc\222.txt", FileMode.Create, FileAccess.Write, FileShare.None);
byte []farr = new byte[1024];
const int rbuffer=1024;
//fs1.ReadByte(); //读取单个字节,返回-1表示读完
while (fs1.Read(farr, 0, rbuffer)!=0) //返回0表示读完
{
fs2.Write(farr, 0, rbuffer);
}
fs1.Close();
fs2.Close();