我的程序:检查 Settings.txt 文件。如果文件不存在,请创建文本并自动写入。如果 Settings.txt 文件已经存在,请忽略。不要在现有文件中创建或写入。
我的问题:当文件不存在时,Settings.txt 文件创建但它是空的。我希望程序在创建文件时写入其中。谢谢你的帮助。
private void Form1_Load(object sender, EventArgs e)
{
string path = @"C:\Users\Smith\Documents\Visual Studio 2010\Projects\Ver.2\Settings.txt";
if (!File.Exists(path))
{
File.Create(path);
TextWriter tw = new StreamWriter(path);
tw.WriteLine("Manual Numbers=");
tw.WriteLine("");
tw.WriteLine("Installation Technical Manual: ");
tw.WriteLine("Performance Manual: ");
tw.WriteLine("Planned Maintenance Technical Manual: ");
tw.WriteLine("Service Calibration Manual: ");
tw.WriteLine("System Information Manual: ");
tw.WriteLine("");
tw.Close();
}
}