Eclipse character encoding(Eclipse 字符编码)
问题描述
我正在使用 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 字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Eclipse 字符编码


基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01