
将utf8转换成ascii
I have a java code and I want to convert it into Utf-8. How can I do it in console. By the way I have multiple files so it need to be do multiple conversion.
我有一个Java代码,我想将其转换为Utf-8。 如何在控制台中执行此操作。 顺便说一下,我有多个文件,因此需要进行多次转换。
获取有关字符集的信息 (Getting Info About Character Set)
We start by getting information about character set. We need to be sure files character set to convert accordingly.
我们首先获取有关字符集的信息。 我们需要确保文件字符集可以进行相应的转换。
$ file -i main.java
main.java: text/plain; charset=us-ascii
file is very useful tool to get information about files like file type, encoding etc.
文件是获取有关文件类型,编码等文件信息的非常有用的工具。
-i is used to get encoding information about file main.java
-i用于获取有关文件main.java的编码信息
列出iconv支持的编码(List Supported Encodings of iconv)
We will use iconv to conversation. But we need to know which encodings are supported by iconv .
我们将使用iconv进行对话。 但是我们需要知道iconv支持哪些编码。
$ iconv -l
Whooa there is a lot of options to use but we think that ASCII and UTF-8 is enough for now.
Whooa有很多选择可以使用,但我们认为ASCII和UTF-8到目前为止已经足够。
将ASCII转换为UTF-8 (Convert ASCII to UTF-8)
We will convert our java code by providing from and to encodings.
我们将通过提供和编码来转换Java代码。
[email protected]:~# iconv -f us-ascii -t UTF8 main.java -o main-out.java
iconv is the tool to convert
iconv是转换工具
-f us-ascii is the source file encoding type
-f us-ascii是源文件编码类型
-t UTF8 is target encoding type
-t UTF8是目标编码类型
main.java is our source file to be converted
main.java是我们要转换的源文件
main-out.java is new file encoded with UTF8
main-out.java是用UTF8编码的新文件
转换多个文件编码(Convert Multiple Files Encoding)
We can make things automated with simple bash scripting help.
我们可以通过简单的bash脚本帮助使事情自动化。
[email protected]:~# for files in *.java ; do iconv -t UTF8 $files -o $files; done
*.java is source files to be converted with java extension
* .java是要使用java扩展名转换的源文件
UTF8 is the destination encoding to be used.
UTF8是要使用的目标编码。
如何在Ascii和Utf-8 Infografic之间转换文件 (How Convert Files Between Ascii and Utf-8 Infografic)

将utf8转换成ascii