gpt4 book ai didi

c# - 使用 C# 在特定目录中创建一个 .txt 文件

转载 作者:行者123 更新时间:2023-11-30 13:46:03 24 4
gpt4 key购买 nike

<分区>

我编写了以下程序来在特定目录中创建一个 .txt 文件。但是我无法创建文件。我什至将路径更改为字符串 fileName = @"D:\\abc.txt"; ,程序编译但未创建该特定目录的文件。

谁能帮我找出可能是什么错误?

namespace SimpleLicense
{
class Program
{
static void Main(string[] args)
{

string fileName = @"C:\\Temp\\abc.txt";

try
{
// Check if file already exists. If yes, delete it.
if (File.Exists(fileName))
{
File.Delete(fileName);
}

// Create a new file
using (StreamWriter sw = File.CreateText(fileName))
{
sw.WriteLine("Installed Date: {0}", DateTime.Now.ToString());
sw.WriteLine("Thermo Licensing System file");

DateTime newDate = DateTime.Now.AddDays(31);
sw.WriteLine("License Expires After"+newDate);

// sw.WriteLine("Add ");
// sw.WriteLine("Done! ");
}

// Write file contents on console.
using (StreamReader sr = File.OpenText(fileName))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com