Eclipse character encoding
Asked Answered
H

3

14

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.

Hedve answered 30/6, 2013 at 0:0 Comment(1)
It means the file has non-printable characters in it, or character set you're using (probably the default) isn't what that file is.Lithe
D
22

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:

enter image description here

Damnatory answered 30/6, 2013 at 0:12 Comment(3)
In your image, it says "Default - inherited (UTF-8)". Is it not UTF-8 then?Valenzuela
@Valenzuela Yes in this case as mentioned in the answer, it is some other encoding than UTF-8Damnatory
By default Run Configuration's enconding inherits workspace's settings. You might be better off changing entire Workspace charset to UTF-8 (Menu>Windows>Preferences: in tab: General>Workspace) as per @Indeliberate answer.Stepper
I
26

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).

Eclipse Preferences - Changing Character Encoding

Indeliberate answered 28/2, 2014 at 16:44 Comment(0)
D
22

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:

enter image description here

Damnatory answered 30/6, 2013 at 0:12 Comment(3)
In your image, it says "Default - inherited (UTF-8)". Is it not UTF-8 then?Valenzuela
@Valenzuela Yes in this case as mentioned in the answer, it is some other encoding than UTF-8Damnatory
By default Run Configuration's enconding inherits workspace's settings. You might be better off changing entire Workspace charset to UTF-8 (Menu>Windows>Preferences: in tab: General>Workspace) as per @Indeliberate answer.Stepper
P
0

If non of the previous answers worked, you could solve that issue by changing your Region settings if you're using Windows 11 OS.

Take a look a here

Plater answered 6/3, 2023 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.