Windows phone 7 我尝试在WP7中使用独立存储在txt文件中保存多行,但它只保存一行,如何保存多行?

Windows phone 7 我尝试在WP7中使用独立存储在txt文件中保存多行,但它只保存一行,如何保存多行?,windows-phone-7,text-files,save,writing,Windows Phone 7,Text Files,Save,Writing,每次比赛结束时,我都用这个来保存分数 IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication(); isf.CreateDirectory("Data"); StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Data\\scoretest.txt", FileMode.Create, isf)); sw.WriteLine(D

每次比赛结束时,我都用这个来保存分数

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
isf.CreateDirectory("Data");
StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Data\\scoretest.txt", FileMode.Create, isf));
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "                                   Score: " + punc);
sw.Close();
为了从txt中读取,我使用了一个for,当读取为空时停止

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
StreamReader sr = null;
try
{
    sr = new StreamReader(new IsolatedStorageFileStream(@"Data\scoretest.txt", FileMode.Open, isf));
    for (;;)
    {
        string x = sr.ReadLine();
        if (x == null)
           break;
        else
            listBox1.Items.Add(x);
    }
    sr.Close();
}
catch
{
    listBox1.Items.Add("");
}

它只对最后一行收费,为什么不读取多行?

FileMode.Create每次都会覆盖该文件。您应该使用FileMode.OpenOrCreate或FileMode.Append(参考:)

另外,请查看隔离存储资源管理器工具以验证您的文件: