本文介绍了关于阅读C#文本文件中的65533的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个示例应用程序,用于在从Openoffice writer粘贴到记事本的过程中加载所有特殊字符.双重代码有所不同,当我尝试加载此代码时.

I created a sample app to load all special characters while copy pasting from Openoffice writer to Notepad. Double codes differs and when I try to load this.

var lines = File.ReadAllLines("..\\ter34.txt");

这会产生65533问题,文本文件包含:

This creates problem of 65533 Issue comes and the text file contains:

  " 

这已更改为符号:

推荐答案

U + FFFD 是如果您尝试读取的数据对于用于将二进制数据转换为文本的编码无效,则使用"Unicode替换字符".

U+FFFD is the "Unicode replacement character", which is used if the data you try to read is invalid for the encoding which is being used to convert binary data to text.

例如,如果您使用ISO-8859-1写入文件,然后尝试使用UTF-8 读取,那么您很容易以一些字节序列结尾,而这些字节序列不是有效的UTF-8.每个无效字节(默认情况下)都将转换为U + FFFD.

For example, if you write a file out using ISO-8859-1, but then try to read it using UTF-8, then you could easily end up with some byte sequences which simply aren't valid UTF-8. Each invalid byte would be translated (by default) into U+FFFD.

基本上,您需要为 File.ReadAllLines 提供正确的编码,作为第二个参数.当然,这意味着您首先需要了解文件的编码.

Basically, you need to provide the right encoding to File.ReadAllLines, as a second argument. That means you need to know the encoding of the file first, of course.

这篇关于关于阅读C#文本文件中的65533的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 18:05