每次比赛结束时我都用它来保存分数
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("");
}
它只对最后一行收费,为什么它读不到多行?