Reputation:
I got a eclipse project that was working OK.
One day I had to format my machine, so I copied my workspace into a backup, after installing eclipse again, I imported my projects from my backed up workspace.
What happened is that it corrupted all the string that contains special characters..
like.. é
, são
, etc.. to É
, são
...
Is there a way to refactor it back to normal?
I tried changing character encoding in eclipse, but it doesn't update the class files.
Upvotes: 2
Views: 6631
Reputation: 108889
Is there a way to refactor it back to normal?
Did you try closing an individual file, right-clicking it to open properties and setting its encoding manually?
like.. é, são, etc.. to É, são...
Are you sure it wasn't É (U+00C9) that was becoming É (U+00C3 U+2030)?
That would suggest that files that were being interpreted as UTF-8 before are now being interpreted as something else (probably windows-1252).
Many Java compilation problems can be fixed by sticking to the subset of values that appear in the US-ASCII character encoding and using Unicode escape sequences for everything else (this assumes you aren't using UTF-16 or UTF-32 or something).
The code String foo = "É";
would become String foo = "\u00C9";
. This improves source code portability at the expense of readability.
You can use the JDK native2ascii tool to perform the conversion:
native2ascii -encoding UTF-8 Foo.java
Upvotes: 2
Reputation: 1108722
You need to reconfigure the workspace encoding. Go to Window > Preferences and enter filter text "encoding" and set to UTF-8 everywhere when applicable, especially the Workspace's text encoding.
Upvotes: 7
Reputation: 4360
How do the actual .java files on disk look? Are they damaged, or is it just that eclipse can't display them properly? If the files look good on disk, setting the encoding property as jjnguy suggest should do the trick.
If the files are damaged on disk, maybe iconv
can "undamage" them?
To avoid such problem in the future, I actually suggest keeping the java files in plain ASCII, using \uNNNN escapes for non-ascii characters in strings etc (e.g. \u00E4 is ä / ä / ä / an a with two dots above).
Upvotes: 0
Reputation: 38586
This is probably a stupid suggestion, but I figured I'd mention it anyways. Are you opening your file.class
or your file.java
? Because the *.class
files, if I recall correctly, are binary files which explains why you're seeing those weird characters. The *.java
files are the plain-text source files.
I figure you knew that, but the wording made me feel otherwise, so I figure I'd mention it.
Upvotes: 0