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.

Derrek Whistle
  • 701
  • 2
  • 7
  • 16
  • 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. – Brian Roach Jun 30 '13 at 00:04

3 Answers3

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

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
HeavyE
  • 2,132
  • 1
  • 23
  • 31
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

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • In your image, it says "Default - inherited (UTF-8)". Is it not UTF-8 then? – GregT May 29 '18 at 09:50
  • @GregT Yes in this case as mentioned in the answer, it is some other encoding than UTF-8 – Juned Ahsan May 29 '18 at 21:59
  • 1
    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 @HeavyE answer. – Witold Kaczurba Aug 29 '18 at 09:47
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