一 FileStream分块读取文件
public byte[] GetFileData(string fileName, long startPosition, long length) { byte[] data; using (FileStream fileRead = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { data = new byte[length]; fileRead.Seek(startPosition, SeekOrigin.Begin); fileRead.Read(data, 0, length); fileRead.Close(); fileRead.Dispose(); } }
二 FileStream追加数据到文件
public void AppendDataToFile(string fileName, byte[] data) { using (FileStream fileSave1 = new FileStream(fileName, FileMode.Append, FileAccess.Write) ) { fileSave1.Write(data, 0, data.Length); fileSave1.Flush(); fileSave1.Close(); fileSave1.Dispose(); } }