FileStream.Write不写入文件 [英] FileStream.Write not Writing to File
问题描述
我正在通过WCF传递一些Base64编码的字符串,并且试图将它们写入文件.但是,尽管我的FileStream对象的Length大于0,但磁盘上的文件仍然为空.
I'm passing some Base64 encoded strings through WCF, and I'm attempting to write them to a file. However, despite the fact that my FileStream object has a Length greater than 0, my file on disk remains empty.
FileStream fs = new FileStream(Config.Instance.SharedSettings.SaveDir + StudyInstance.StudyId + "\\tmp.ext", FileMode.Create);
EncodeBlock eb = new EncodeBlock();
while (eb.Part != eb.OfParts || eb.OfParts == 0)
{
eb.ToDecode = ps.StudyService.GetInstancePart(StudyInstance, s, eb.Part+ 1, Config.Instance.ClientSettings.AppData);
eb = Base64Encoder.Decode(eb);
fs.Write(eb.ToEncode, 0, eb.ToEncode.Length);
}
fs.Close();
eb.ToEncode
的长度始终大于0, fs.Length
的长度始终大于0,但是我的"tmp.ext"
文件已创建,但保持为空. fs.CanWrite
始终也是如此.
eb.ToEncode
's length is always greater than 0, fs.Length
is always greater than 0, and yet my "tmp.ext"
file is created, but remains empty. fs.CanWrite
is always also true.
推荐答案
您是否尝试过调用FileStream.Flush?
Have you tried calling FileStream.Flush?
在关闭流之前调用它.
您还应该使用"using"语句来确保流被清除.
You should also use a "using" statement to ensure the stream is cleaned up.
这篇关于FileStream.Write不写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!