如何将数据附加到 Windows Phone 的独立存储中的同一个文件中 [英] How to append data into the same file in IsolatedStorage for Windows Phone

查看:21
本文介绍了如何将数据附加到 Windows Phone 的独立存储中的同一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想解决的问题:

This is the problem I wanted to solve:

  1. 创建一个文件,添加数据并将其保存在isolatedStorage中.

  1. Create a file, add data and Save it in isolatedStorage.

打开文件,向该文件添加更多数据.

Open the file, add more data to this file.

如何将数据附加到此文件中?新数据会排在旧数据之前吗?

How do I append data into this file? Will the new data line up ahead of the old data?

一些代码将不胜感激.

谢谢

推荐答案

您的代码如下所示(来自您在问题中的评论 - 下次编辑问题并插入代码,使其更具可读性,我们不必转发):

Your code looks like this (from your comment in the question - next time edit the question and insert the code so it's more readable and we don't have to repost it):

StreamWriter writeFile = new StreamWriter(
    new IsolatedStorageFileStream(
        txtBlkDirName.Text + "\\" + strFilenm, 
        FileMode.OpenOrCreate, 
        isf)); 
writeFile.WriteLine(txtPreSetMsg.Text); writeFile.Close(); 

请注意,您使用的模式是 OpenOrCreate,它将打开现有文件并将您的流指针放在开头.如果您立即开始写入,它将覆盖文件中的任何内容.

Note that the mode you use is OpenOrCreate, which is going to open the existing file and put your stream pointer at the start. If you immediately start writing, it's going to overwrite anything in the file.

您的附加选项是:

  • 改用FileMode.Append,这样在打开后指针就已经在流的末尾了
  • 保留现有内容,但在编写之前,调用Seek(0, SeekOrigin.End) 手动将指针移至文件末尾.
  • Use FileMode.Append instead so the pointer is already at the end of the stream after opening
  • Keep what you have but before writing, call Seek(0, SeekOrigin.End) to move the pointer to the end of the file manually.

这篇关于如何将数据附加到 Windows Phone 的独立存储中的同一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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