![](/img/trans.png)
[英]C# File.ReadAllText returning “NotSupportedException”
[英]c# File ReadAllText only reads first Char
在目前的发展中,我遇到了严重的问题。
在我的硬盘上的一堆书面文件中,我想读出他们的内容并将其写入文本框。 接缝非常容易,但不知怎的,我陷入了困境:
这些文件包含如下内容:“ <LogItem><Row Number="0"><Column Name="object_id"><Old Value="2317"/><New Value="2317"/>
”
我读了他们:
textBox1.Text = File.ReadAllText(filetoread);
这个“ReadAllTest”的结果只是第一个Char“<”其他所有未写入文本框的内容。 手动我可以使用普通编辑器读取文件,这会显示完整的文本。
没有看到任何陷阱或限制吗?
最好的祝福
这可能是一个编码问题......很少但不是不可能......一次尝试一个:
textBox1.Text = File.ReadAllText(filetoread, Encoding.Unicode);
textBox1.Text = File.ReadAllText(filetoread, Encoding.BigEndianUnicode);
textBox1.Text = File.ReadAllText(filetoread, Encoding.UTF32);
textBox1.Text = File.ReadAllText(filetoread, Encoding.UTF8);
textBox1.Text = File.ReadAllText(filetoread, Encoding.Default);
如果xanatos的答案不起作用,请尝试以下方法:
using (StreamReader read = new StreamReader(filetoread))
{
textBox1.Text = read.ReadToEnd();
}
你可以看到它没有使用File.ReadAllText()
。 而且,这将有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.