写入后文件不存在

时间:2014-02-14 06:34:01

标签: c# windows-phone

我有以下代码:

try
{
    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    {
        StreamWriter output = new StreamWriter(new IsolatedStorageFileStream(filename,           FileMode.OpenOrCreate, store));
        Console.WriteLine(name + ";" + positions + ";" + courier + ";" + deliverydate + ";" + submissiondate);
        output.Flush();
        output.Close();
        output.Dispose();
     }
 }
 catch (Exception exf)
 {
     MessageBox.Show("Error occured while saving your delivery. Unregistered Delivery");
 }

我在文件中保存字符串。但是当我在编写它之后立即尝试阅读它时,该文件似乎不存在。

 try
 {
     using (var store = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (TextReader reader = new StreamReader(store.OpenFile(filename, FileMode.Open, FileAccess.Read, FileShare.None)))
         {
              while (reader.Peek() != -1)
              {
                  MessageBox.Show(reader.ReadLine());
              }
              reader.Close();
          }
      }
 }
 catch (Exception ex)
 {
     MessageBox.Show(ex.Message);
 }

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

您不是在文件中而是在控制台中写入数据。从此

更改您的代码
Console.WriteLine(name + ";" + positions + ";" + courier + ";" + deliverydate + ";" + submissiondate);

到那个:

output.WriteLine(name + ";" + positions + ";" + courier + ";" + deliverydate + ";" + submissiondate);