1
Names               Date               Time
Sandra              11/18/2013         10.12AM
Denise              12/21/2013         10.10PM
Prnikshenth         11/11/2019         12.00AM

using System;
using System.Collections;
using System.IO;
class FunWithScheduling
{
       public void AddView()
       {
                  FileStream s = new FieStream("Scheduler.txt",FileMode.Append,FileAccess.Write);
                  StreamWriter w = new StreamWriter(s);
                  Console.WriteLine("Enter the Name of the Person To Be Met:");
                  string name = Console.ReadLine();
                  w.Write(name);
                  w.Flush();
                  w.Close();
                  s.Close();
       }
       public static void Main(string[] args)
       {
           FunWithScheduling a = new FunWithScheduling();
           a.AddView();
       } 
}      

我使用此代码添加了一个名称,但它是这样存储的

Names               Date               Time
Sandra              11/18/2013         10.12AM
Denise              12/21/2013         10.10PM
Prnikshenth         11/11/2019         12.00AMShawn

我添加了肖恩,但这就是它被时间卡住的方式。

4

2 回答 2

1

您需要先写入新行。我还添加了using语句,因此您不必close手动调用。

using (StreamWriter sw = File.AppendText(@"Scheduler.txt"))
{
   sw.Write(Environment.NewLine + name);
}
于 2013-08-03T13:36:49.813 回答
-1

尝试以下可能有帮助的解决方案

string line = name + "\t" + DateTime.Now.Date.ToString() + "\t" + DateTime.Now.Time.ToString();

w.WriteLine(line );

您可能只需要分别检查日期和时间的格式。

于 2013-08-03T13:35:25.543 回答