首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IsolatedStorageFile给出异常

IsolatedStorageFile给出异常
EN

Stack Overflow用户
提问于 2011-06-22 21:43:09
回答 1查看 274关注 0票数 0

在windows phone7中,我试图写入一个文件,然后尝试从一个文件中读取,但在读取时给出了下面的异常。

代码语言:javascript
复制
public static void writeToFile(String videoUrl)
{
    IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
    store.CreateDirectory("MyFolder");
    IsolatedStorageFileStream stream = new IsolatedStorageFileStream("MyFolder\\data.txt", FileMode.Append, 
                                            FileAccess.Write, store);
    StreamWriter writer = new StreamWriter(stream);
    writer.WriteLine(videoUrl);
}

public static void readFromFile()
{
    try
    {
        IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream stream = new IsolatedStorageFileStream("MyFolder\\data.txt", FileMode.Open,
                                                 store);
        StreamReader reader = new StreamReader(stream);
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            Debug.WriteLine("kkkkkk-----------------" + line); // Write to console.
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine("ESPNGoalsUtil::readFromFile : " + ex.ToString());
    }

}

例外:

代码语言:javascript
复制
System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, IsolatedStorageFile isf)
   at ESPNGoals.Utility.ESPNGoalsUtil.readFromFile()

我正在写文件,然后用同样的方法读取文件,而不是关闭模拟器。

EN

回答 1

Stack Overflow用户

发布于 2012-06-19 04:09:09

writeToFile返回之前,您需要在StreamWriter上调用Close (或者最好将代码包装在using块中)。

这同样适用于readFromFile中的StreamReader

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6440855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档