How to change the encoding of multiple files from ISO-8859-1 to UTF-8?

Asked

Viewed 20,486 times

0

I have a project (in java) with more than 100 files, some of them are in ISO others in UTF8.

How to change the encoding of all ISO files to UTF-8 without losing the special characters ?

2 answers

3

If you are using the Eclipse:

  1. Open Eclipse with your project;
  2. In the tab of "Project Explorer", right click and select "Properties";
  3. In the left menu, choose "Resource" and the right, in "Text File Encoding" choice UTF-8;
  4. OK in all things;

If you’re in the Netbeans:

  1. Open Netbean with your project;
  2. On the tab "Projects" right click and select "Estates";
  3. In the menu on the left, select "Source Code" and the right, right at the bottom, change the "Coding" for UTF-8;

As you said your project has more than 100 files in different encoding than UTF-8, and you will change them, it is very likely that a lot of special characters will break (even if you don’t want to). For example: "á" can flip " ". What’s more, if you compile your software, you may have an error of unmappable Character.

Take a test in Netbeans, I did some tests here and didn’t break the special characters, unlike Eclipse.

  • UTF-8 includes all ISO-8859-1 characters, so any well-made converter should be able to convert all files without error characters.

  • I did three tests here converting "áãâéêííóú". Notepad++, Eclipse and Netbeans. All tests converting from ISO-8859-1 to UTF-8. Result: Break in Notepad++ and Eclipse. In Netbeans, conversion did not break special characters.

  • If the conversion is well done, it won’t break. I did the Notepad++ experiment and it works. (explicitly choose "Convert to UTF-8", not "Encode in UTF-8")

  • Correct @luiscubal. I just changed the encoding.

1

It is good to configure your editor to use the correct encoding later, but initially it is much better to convert the files automatically.

If you’re on a Unix, just use recode:

$ recode utf8 *.java

To process recursively:

$ find . -name "*.java" -exec recode utf8 {} \;

The recode is quite flexible, you can do a lot more things. Credits to this reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.