将utf8转换成ascii_如何在Ascii和Utf-8之间转换文件

将utf8转换成ascii

将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)

How Convert Files Between Ascii and Utf-8 Infografic
How Convert Files Between Ascii and Utf-8 Infografic
如何在Ascii和Utf-8 Infografic之间转换文件
LEARN MORE  How To Use Linux Xxd Command Tutorial For Hex and Binary Operations With Example?
了解更多信息如何在示例中使用Linux Xxd命令教程进行十六进制和二进制操作?

翻译自: https://www.poftut.com/convert-files-ascii-utf-8/

将utf8转换成ascii

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值