事件触发器未写入资源文件夹中的 .txt 文件 - 问题已解决
我遇到了事件触发器问题,该触发器应该写入资源文件夹中的 .txt 文件。但是,没有数据写入指定文件夹。经过一番调查,我意识到代码运行正常,但 .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);
}
}
更新:
经过进一步检查,我意识到 .txt 文件是在调试文件夹中创建的,而不是在资源文件夹中创建的。这种疏忽导致人们对为什么数据没有按预期写入感到困惑。
感谢您提供的帮助,我已将此问题标记为已解决。谢谢你!
I encountered an issue with an event trigger that was supposed to write to a .txt file within my resource folder. However, no data was being written to the designated folder. After some investigation, I realized that the code was functioning correctly, but the .txt file was being created in the debug folder, not the resource folder as I initially assumed.
Here's the original code snippet:
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);
}
}
Update:
Upon further inspection, I realized the .txt file was being created in the debug folder, not the resource folder. This oversight led to confusion regarding why the data wasn't being written as expected.
I appreciate the assistance provided, and I've marked this issue as resolved. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下方法:
来自
microsoft
此处
You can use this method:
}
from microsoft
Here