13

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
  • 671
  • 2
  • 6
  • 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

2 Answers2

24

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
  • 35,466
  • 40
  • 150
  • 172
HeavyE
  • 2,052
  • 1
  • 22
  • 30
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
  • 35,466
  • 40
  • 150
  • 172
Juned Ahsan
  • 66,028
  • 11
  • 91
  • 129
  • 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