Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text corrupt after changing the Eclipse to UTF-8 Encoding

I had to change the Eclipse Indigo encoding to UTF-8. Now all the spécial characters as éàçè are replaced with �.

I can do a search and replace but I wonder if there is better solution.

Thanks

like image 353
Momo Avatar asked Jul 17 '12 14:07

Momo


2 Answers

Changing the encoding in Eclipse doesn't change your existing files : it only changes the way Eclipse reads them.

What you need is to convert your old files to UTF-8 as well as configuring Eclipse.

There are some tools to do that and you may write a small java program too.

If you want to use an existing tool, here's the first I found : http://www.marblesoftware.com/Marble_Software/Charco.html (you could find a better one for your (unspecified) OS.

If you want to write a tool yourself (about 20 LOC), the thing to know is that you must :

  • read the file with their initial charset
  • write the files in UTF-8

Here's the core of the operation :

  reader = new BufferedReader(new InputStreamReader(new FileInputStream(...), "you have to know it"));
  writer = new OutputStreamWriter(new FileOutputStream(...), "UTF-8"); 
  String line;
  while ((line=reader.readLine())!=null) {
     writer.write(line);
  }
like image 102
Denys Séguret Avatar answered Oct 06 '22 01:10

Denys Séguret


I recommend notepad++ for conversion. This is an editor which has some very useful/powerful view and conversion tools to troubleshoot charsets. Also some more "swiss-knife"-like functions (file comparison, advanced search and replace and many more...)

notepad++

like image 25
OptimusPrime Avatar answered Oct 06 '22 01:10

OptimusPrime