为什么不读取整个文本文件
本文关键字:文本 文件 读取 为什么不 | 更新日期: 2023-09-27 18:26:40
在C#中,我想将.tga图片读取到字符串变量中。我使用了许多变体来读取文本文件,但每种解决方案都有问题。文件大小17Kb为什么不阅读全文?
例如,这不起作用:
string item = "";
while ((item = sr.ReadLine()) != null)
{
picture_string += sr.ReadLine()+"";
}
它不起作用:
picture_string = sr.ReadToEnd();
不起作用
picture_string = File.ReadAllText(path);
您尝试读取的文件是二进制文件,而不是文本。停止将二进制文件当作文本文件来读取。
var fileContents = File.ReadAllBytes(path);