如何使用不同的编码转换(Java)文件相同? [英] How to convert (Java) files with different encodings to the same?

查看:117
本文介绍了如何使用不同的编码转换(Java)文件相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Eclipse中使用一个大型的Java Web应用程序,其文件具有不同的编码:一些是UTF-8,另外一些在Cp1252中,其他的则在ISO-8859-1中(没有区分JSP或java源文件或CSS)—但是我知道每个文件的编码。



我将项目转换为Maven,这是一个很好的机会,将它们全部转换为UTF-8。 br>
当然我不想失去一个字符(所以完全自动化的转换不适用于这里)。



我该怎么做?有没有一个工具可以帮助我确保我不会失去任何特殊的角色?

webapp是意大利语,所以特别是在JSP中,可能会有很多重音字母(可能不是所有的HTML实体已被使用)



该项目在Eclipse中,但如果可以使转换更容易,我可以使用外部编辑器。

解决方案

转换单个文件可以通过 iconv功能(我使用 LibIconv for Windows ) 。



它允许您指定源代码和目的地编码,并在不能转换字符时发出警告。



我尝试使用几个源文件,所有重音字母都是从Cp1252以UTF-8正确转换。


I'm working on a big java web application in Eclipse, whose files have different encodings: some are in UTF-8, others in Cp1252, yet others are in ISO-8859-1 (with no distinction between JSP's or java source files, or CSS) — but I know the encoding of each file.

I'm converting the project to Maven, and this is a great occasion to turn all of them to UTF-8.
Of course I don't want to lose a single character (so fully automated conversions do not apply here).

How should I go about it? Is there a tool that can help me ensure I don't lose any special character?
The webapp is in Italian, so, especially in JSP's, there could be lots of accented letters (probably not everywhere HTML entities have been used).

The project is in Eclipse, but I can use an external editor if that could make the conversion easier.

解决方案

Converting a single file can be done with the iconv function (I used LibIconv for Windows).

It lets you specify the source and destinations encodings, and warns when characters can't be converted.

I tried it with a couple of source files and all the accented letters were correctly converted in UTF-8 from Cp1252.

这篇关于如何使用不同的编码转换(Java)文件相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆