代码改变世界

c# 获取文件内容

2017-07-14 16:58  伟大的程序员2  阅读(369)  评论(0编辑  收藏  举报

List<byte[]> datalist = new List<byte[]>();
public List<byte[]> ftest(string filename)
{
List<byte[]> array = new List<byte[]>();
FileStream fs = new FileStream(filename, FileMode.Open);
BinaryReader read = new BinaryReader(fs);
try
{
int index = 0;
while (fs.Length > index)
{
int lenght = (int)fs.Length - index < 80 ? (int)fs.Length - index : 80;
byte[] buff = read.ReadBytes(lenght);
array.Add(buff);
index += lenght;
}
}
catch (Exception ex)
{
LogClassFunctions.SendDataToLog(false, "-update", "", ex.Message);
// MessageBox.Show(ex.Message);
}
finally
{
read.Close();
fs.Close();


}
return array;
}