0

我正在尝试创建一个从 .txt 文件加载数据的二维整数数组,但是当它编译这行代码时:string line = stream.ReadLine();它给了我线程标题中的错误,还有这个:

尝试访问方法失败,System.IO.StreamReader..ctor(System.String)

我知道在 PC 和 WP7/360 之间使用 txt 文件之间可能存在差异,但是我确信这是可能的,因为我的大学导师在他的 WP7 手机上制作的应用程序使用了 .txt 文件,我必须做出哪些改变Windows Phone 正确读取文件?

对于那些想要额外信息的人来说,这里是将 txt 加载到 int 数组的整个方法:

    public void loadMap(string mapFileName)
    {
        int x = 0, y = 0;

        StreamReader stream = new StreamReader(mapFileName);

        do
        {
            string line = stream.ReadLine();
            string[] numbers = line.Split(',');

            foreach (string e in numbers)
            {
                int tile = int.Parse(e);
                this.tileID[x, y] = tile;

                x++;
            }
            y++;
        }
        while (!stream.EndOfStream);
        xSize = x;
        ySize = y;

        stream.Close();

    }

编辑
现在取得了一些进展,尽管我通过使用 IsolatedStorage 方法遇到了一个新错误,但我在解析代码之前添加了以下代码:

    var store = IsolatedStorageFile.GetUserStoreForApplication();
    var readStream = new IsolatedStorageFileStream(mapFileName, FileMode.Open, store);
    var stream = new StreamReader(readStream);  

现在在这里:var readStream = new IsolatedStorageFileStream(mapFileName, FileMode.Open, store);我收到错误:

不允许对 IsolatedStorageFileStream 进行操作。

有任何想法吗?

4

1 回答 1

1

出于安全原因,Windows Phone 上的应用程序是沙盒化的,这实际上只是意味着您无法触摸不属于您的东西。考虑改用 XNA 的StorageContainer类,它旨在解决非 PC 平台固有的安全限制。

更新

经过进一步调查,Windows Phone 似乎不提供此功能。相反,您应该使用System.IO.IsolatedStorage该类。

于 2012-08-20T18:31:16.293 回答