Windows Phone 7:文件流异常 [英] Windows Phone 7 : FileStream exception

查看:20
本文介绍了Windows Phone 7:文件流异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 FileStream(使用命名空间 System.IO),但出现异常:

I try to use FileStream (using namespace System.IO) but I get an exception :

Attempt to access the method failed 

代码如下:

FileStream fs = new FileStream("file.txt", FileMode.Create); 

我在 microsoft.com 上搜索,发现这个错误是因为我使用了错误的库引用.

I searched on microsoft.com and I found that this error is because I use a bad library reference.

但在我的项目中,我使用来自文件夹的 mscorlib.dll 进行编译:C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0

But in my project, I compile with mscorlib.dll from folder : C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0

我需要帮助,请.

推荐答案

您将需要使用 IsolatedStorage,例如:

You will need to use IsolatedStorage, for example:

置于文件顶部:

using System.IO.IsolatedStorage;

然后在你的方法中这样做:

Then in your method do this:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var istream = new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, store))
    {
        using (var sw = new StreamWriter(istream))
        {
            sw.Write("Some Stuff");
        }
    }
}

这里和其他操作的一个很好的例子和解释可以在这里找到:http://msdn.microsoft.com/en-us/library/cc265154(v=VS.95).aspx#Y300

A great example and explanation of this and other operations can be found here: http://msdn.microsoft.com/en-us/library/cc265154(v=VS.95).aspx#Y300

您可以使用 Windows Phone 7 IndependentStorageExplorer

开始编写文档的好地方:http://msdn.microsoft.com/library/ff626516(v=VS.92).aspx

A good place to start for documentation: http://msdn.microsoft.com/library/ff626516(v=VS.92).aspx

也在这里:http://create.msdn.com/en-us/education/文档

这篇关于Windows Phone 7:文件流异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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