【问题标题】:WP7 Isolated Storage Text Document Read LineWP7 隔离存储文本文档读取行
【发布时间】:2011-09-30 00:22:33
【问题描述】:

有没有办法使用独立存储(即文本文档)来获取某一行上的文本。 我想将变量保存到我的应用程序设置页面上的文本文档中。然后回到主页面,读取第 3 行保存的变量。我已经知道如何保存它们了。只是不读某些行。

如果我关闭并重新打开应用程序,我的应用程序创建的文本文档还会在那里吗?

【问题讨论】:

    标签: c# windows-phone-7 storage


    【解决方案1】:

    试试这个

    using( TextReader reader = new StreamReader( 
             new IsolatedStorageFileStream( "myFile.txt", System.IO.FileMode.Open, 
               IsolatedStorageFile.GetUserStoreForApplication() ) ) {
    
        string line = reader.ReadLine(); // first line, discard
        line = reader.ReadLine();        // second line, discard
        line = reader.ReadLine();        // third line, read the variable value
    }
    

    但是,您最好使用IsolatedStorageSettings 类来存储设置(链接包含示例用法)。另一种选择是将所有设置放入可序列化的类中并使用XmlSerializer 保存/读取设置。这两种方法都不需要手动解析文件。

    【讨论】:

    • 当我关闭应用程序并重新打开它时,文档是否也保存了?谢谢
    • @Al3xhamilton 如果您使用IsolatedStorageSettings,框架会在应用退出时自动为您保存。使用您的方法和XmlSerializer,您需要手动保存更改。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多