在 Windows Phone 8 SD 卡上读取文件的问题 [英] Issue with reading file on Windows Phone 8 SD card

查看:54
本文介绍了在 Windows Phone 8 SD 卡上读取文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读取 Windows Phone SD 卡上的文件时遇到问题.我使用 ExternalStorageFile.OpenForReadAsync 获取有效的 Stream 对象.然而,尽管流 CanSeek 属性为真,但任何搜索操作都会被忽略并且位置不会移动;

I have problems reads the file on Windows Phone SD card. I get the valid Stream object using ExternalStorageFile.OpenForReadAsync. However any seek operation is ignored and position is not moved although the stream CanSeek property is 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.

// both curPos and pos are 0.

推荐答案

我也遇到了同样的问题.Seek 在 Microsoft.Phone.Storage.NativeFileStream 中确实被破坏了,它是 SD 卡上文件的流类型.最后我用ILspy看了一下类,就是这样:

I was fighting with the very same problem. Seek is indeed broken in Microsoft.Phone.Storage.NativeFileStream, which is the type of stream for files on SD card. In the end I looked at the class with ILspy, and this is it:

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

And function SetFilePointer: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365541%28v=vs.85%29.aspx

为了使seek工作,偏移值应该在long的高32位.

To make seek work, offset value should be in higher 32bits of the long.

这篇关于在 Windows Phone 8 SD 卡上读取文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆