2019 年 Visual Studio 写入资源文件夹中的 txt 文件
Writing to a txt file in resource folder in Visual Studio 2019
我在尝试写入资源文件夹中的 txt 文件时遇到问题,我是 C# 和 Visual Studio 的新手,所以我很迷茫,希望得到任何帮助。问题很简单,没有任何内容写入 txt 文件。
private void button1_Click(object sender, EventArgs e)
{
int b = numericUpDown1.GetHashCode();
int c = numericUpDown2.GetHashCode();
int d = numericUpDown3.GetHashCode();
try
{
StreamWriter sw = new StreamWriter("orders.txt");
sw.WriteLine("Burger(s) " + b);
sw.WriteLine("Chip(s): " + c);
sw.WriteLine("Drink(s) " + d);
sw.Close();
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}
你可以使用这个方法:
class WriteAllLines
{
public static async Task ExampleAsync()
{
string[] lines =
{
"First line", "Second line", "Third line"
};
await File.WriteAllLinesAsync("WriteLines.txt", lines);
}
}
来自微软
我在尝试写入资源文件夹中的 txt 文件时遇到问题,我是 C# 和 Visual Studio 的新手,所以我很迷茫,希望得到任何帮助。问题很简单,没有任何内容写入 txt 文件。
private void button1_Click(object sender, EventArgs e)
{
int b = numericUpDown1.GetHashCode();
int c = numericUpDown2.GetHashCode();
int d = numericUpDown3.GetHashCode();
try
{
StreamWriter sw = new StreamWriter("orders.txt");
sw.WriteLine("Burger(s) " + b);
sw.WriteLine("Chip(s): " + c);
sw.WriteLine("Drink(s) " + d);
sw.Close();
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}
你可以使用这个方法:
class WriteAllLines
{
public static async Task ExampleAsync()
{
string[] lines =
{
"First line", "Second line", "Third line"
};
await File.WriteAllLinesAsync("WriteLines.txt", lines);
}
}
来自微软