两者StreamReader
和BinaryReader
可用于获得来自二进制文件的数据(例如)
BinaryReader在:
using (FileStream fs = File.Open(@"c:\1.bin",FileMode.Open))
{
byte[] data = new BinaryReader(fs).ReadBytes((int)fs.Length);
Encoding.getstring....
}
StreamReader的:
using (FileStream fs = File.Open(@"c:\1.bin",FileMode.Open))
{
using (StreamReader sr = new StreamReader(fs,Encoding.UTF8))
{
var myString=sr.ReadToEnd();
}
}
有什么区别,我应该何时使用哪种?