gpt4 book ai didi

C# 正在 Visual Studio 中编写文件,但在我发布文件时却没有

转载 作者:行者123 更新时间:2023-11-30 12:31:11 25 4
gpt4 key购买 nike

我有以下代码,应该通过组织列表对每个组织进行 td,对每个组织调用 toString 方法,并将结果打印到控制台和名为 Debug1.tab 的文件。

try
{
StreamWriter print = File.CreateText("Debug1.tab");
Console.WriteLine(LinkedInClass.isThrottled);
int p = 1;
foreach (Org org in orgList)
{
try
{
if (org.numContacts > 0)
{
Console.WriteLine(org.ToString());
print.WriteLine(org.ToString());
}
}
catch (Exception) { Console.WriteLine(e.StackTrace); Console.WriteLine(e.Message); Console.ReadKey();}
}
print.Close();
Console.WriteLine("There were " + orgList.Count + " organizations in the list." + LinkedInClass.numWithContacts + " of which I found contacts for. Throttling was "+(LinkedInClass.isThrottled?"":"not ")+"encountered.");
break;
}
catch (Exception e) { Console.WriteLine(e.StackTrace); Console.WriteLine(e.Message); Console.ReadKey(); }

在 Visual Studio 中,它运行良好,但当我发布它时,程序不会创建文件或写入文件。它仍在写入控制台,catch 语句未执行,并且在它应该关闭 streamWriter 后立即正确打印到控制台。

最佳答案

你指定文件名的方式(不给出路径),文件是在当前工作目录中创建的,这可能与你的应用所在的目录不同。使用search your disk可能有助于查看文件是否在别处创建。

无论如何:在创建文件时指定一个路径,以确保它始终位于您期望的位置(并且不要使用 Program Files 文件夹,而是一些可公开写入的文件夹)。

关于C# 正在 Visual Studio 中编写文件,但在我发布文件时却没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14278400/

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