views:

133

answers:

4

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.

A: 

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.

Jorge Israel Peña
figures........
Adriaan Koster
A: 
Rasmus Kaj
irrelevant. it's just that the encoding isn't set properly.
Bozho
Do you know that, Bozho? I know for a fact that eclipse can mess upp files on disk, and I don't see anything in the OP that ascertains that it is just the display that's broken.
Rasmus Kaj
+2  A: 

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.

BalusC
+1  A: 

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
McDowell