gpt4 book ai didi

c# - streamwriter 不写入文件

转载 作者:太空宇宙 更新时间:2023-11-03 10:29:53 24 4
gpt4 key购买 nike

string directoryPath = @"D:\Tools\Examples";
using (StreamWriter file = new StreamWriter(@"C:\Users\gdarmon\Desktop\MacbethTest.txt",true))
{
foreach (string rawImagePath in Directory.GetFiles(directoryPath, "*.raw").Select(Path.GetFullPath))
{
image.ReadHeaderLessImage(rawImagePath, width, height, colorOrder, bpp);

List<MacbethCheckerBatchesColor> resultWithOutExtraLines =
wrapper.DetectMacbethColorChecker(image.Data, image.Width, image.Height, image.ColorOrder,
image.Bpp, showResult, batchFillFactor);
if (resultWithOutExtraLines == null)
{
file.WriteLine(rawImagePath);
}
}
}

这是我的代码,我试图将无法正常工作的文件的名称写入文件。该文件原来是空的。虽然我点击了 file.writeline 行。
你能看出我的错误吗?
我按照这个例子
https://msdn.microsoft.com/en-us/library/8bh11f1k.aspx

最佳答案

您发布的代码应该可以工作。

如果您试图在代码运行时检查文件的内容(例如,如果您设置了断点),流将不会被刷新,这意味着它实际上不会向文件还没有。

如果你想在调试时看到文件的内容,你应该在WriteLine之后调用Flush方法:https://msdn.microsoft.com/fr-fr/library/system.io.streamwriter.flush(v=vs.110).aspx

 file.WriteLine(rawImagePath);
file.Flush();
// add a breakpoint after here: the file will have contents

关于c# - streamwriter 不写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30575270/

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