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 に答える