我有一个文本文件,里面只有一个字符“T”,我创建了一个读取流以将正在读取的内容输出到控制台,我得到了 239、187、191 和 84,我知道 84 代表'T',我知道 239、187、191 也代表其他字符,但我的文本文件中没有这些字符,这是怎么回事??
public class Test {
public static void main(String args[]) throws IOException {
FileInputStream in = null;
try {
in = new FileInputStream("input.txt");
int c;
while ((c = in.read()) != -1) {
System.out.println(c);
}
}finally {
if (in != null) {
in.close();
}
}
}
}
最佳答案
你确定不是239 187 191
吗? (EF BB BF
十六进制)
您看到的是 byte order mark文件的:
The byte order mark (BOM) is a Unicode character, U+FEFF BYTE ORDER MARK (BOM), whose appearance as a magic number at the start of a text stream can signal several things to a program reading the text:
The byte order, or endianness, of the text stream;
The fact that the text stream's encoding is Unicode, to a high level of confidence;
Which Unicode encoding the text stream is encoded as.
关于java - 为什么 FileReader 流从文本文件中读取 237、187、191?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53303571/