我在
Windows Phone SD卡上读取文件时遇到问题.我使用ExternalStorageFile.OpenForReadAsync获取有效的Stream对象.但是,虽然流CanSeek属性为true,但忽略任何搜索操作并且不移动位置;
private async void ReadFileOnSDCard(ExternalStorageFile file)
{
Stream stream = await file.OpenForReadAsync();
using (stream)
{
long curPos= stream.Seek(100, SeekOrigin.Begin);
long pos = stream.Position;
// curPos和pos都是0.
最佳答案 我正在与同样的问题作斗争.在Microsoft.Phone.Storage.NativeFileStream中确实破坏了Seek,这是SD卡上文件的流类型.最后我用ILspy查看了这个类,这就是它:
public override long Seek(long offset, System.IO.SeekOrigin origin)
{
...
uint num = (uint)((ulong)(offset & -4294967296L) >> 32);
uint num2 = (uint)(offset & (long)((ulong)-1));
uint num3 = NativeFileStream.SetFilePointer(this.m_handle, num, ref num2,
...
}
和函数SetFilePointer:http://msdn.microsoft.com/en-us/library/windows/desktop/aa365541%28v=vs.85%29.aspx
为了使搜索工作,偏移值应该在更长的32位.