问题描述
我正在使用 Scanner 扫描 Java 中的 .txt 文档.但是,当我在 Eclipse 中打开 .txt 文档时,我注意到一些字符无法识别,并且它们被替换为如下所示的内容:
I am using Scanner to scan a .txt document in Java. However, when I open the .txt document in Eclipse, I notice some characters are not being recognized, and they are replaced with something that looks like this:
这些字符甚至不会让我将文件扫描为
These characters won't even let me scan the file as
while(scan.hasNext)
自动返回false(如果这些字符不存在,那么我可以扫描文档就好了).
automatically returns false (if these characters are not present, then I can scan the document just fine).
那么,我如何让 Eclipse 识别这些字符以便我可以扫描?我无法手动删除它们,因为文档很大.谢谢.
So, how do I get Eclipse to recognize these characters so I can scan? I can't manually remove them because the document is quite large. Thanks.
推荐答案
您正在阅读的文件必须包含 UTF-8 或其他一些编码字符,当您尝试在控制台上打印它们时,您会得到一些字符为'.这是因为 eclipse 中默认的控制台编码不是 UTF-8.您需要通过转到运行配置 -> 通用 -> 编码 -> 从下拉列表中选择 UTF-8 来设置它.检查以下屏幕截图:
The file you are reading must be containing UTF-8 or some other encoding characters and when you try to print them on console then you will get some characters as �'. This is because the default console encoding is not UTF-8 in eclipse. You need to set it by going to Run Configuration -> Common -> Encoding -> Select UTF-8 from the drop down. Check below screenshot:
这篇关于Eclipse 字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!