Eclipse character encoding

陌路散爱 提交于 2019-12-17 16:27:46

问题


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)

automatically returns false (if these characters are not present, then I can scan the document just fine).

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.


回答1:


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:




回答2:


If you need to change the character encoding for your entire Eclipse Workspace, go to Window -> Preferences. Then under General -> Workspace, change the 'Text file encoding' to the appropriate character encoding (in this case, UTF-8).



来源:https://stackoverflow.com/questions/17385818/eclipse-character-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!