using (var writer = File.CreateText(fullFilePath))
{
file.Write(fileContent);
}
给定以上代码,是否可以从中得知文件大小StreamWriter
?
是的,您可以尝试以下方法
long length = writer.BaseStream.Length;//will give unexpected output if autoflush is false and write has been called just before
注意:writer.BaseStream.Length
属性可能会返回意外结果,因为StreamWriter
不会立即写入。它进行缓存,以便获得所需的预期输出AutoFlush = true
writer.AutoFlush = true; or writer.Flush();
long length = writer.BaseStream.Length;//will give expected output
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句