我想以字节为单位获取隔离存储中文件的大小。还需要将该文件作为每个 1024 字节的块读取。我怎样才能做到这一点?
问问题
641 次
1 回答
1
public static IsolatedStorageFileStream OpenFile(string filePath)
{
IsolatedStorageFileStream fileStream = null;
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!store.FileExists(filePath))
{
return fileStream;
}
else
{
fileStream = store.OpenFile(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
}
return fileStream;
}
void ReadFile()
{
using (var streamReader = OpenFile(filePath))
{
using (BinaryReader reader = new BinaryReader(streamReader))
{
byte[] buffer = new byte[1024];
int fileLen = (int)reader.BaseStream.Length;
int readCount=0;
while (fileLen > 0)
{
readCount = reader.Read(buffer, 0, buffer.Length);
fileLen = fileLen - readCount;
//Do what ever with buffer
}
}}}
于 2012-09-12T11:12:24.657 回答