简体   繁体   English

java中如何将一个充满ASCII的文件转换成一个充满字符的文件

[英]How to convert a file full of ASCII to a file full of characters in java

I have a file in which there are ASCII like this: enter image description here Now I want to read this file and convert these ASCII to characters.我有一个文件,其中有这样的 ASCII:在此处输入图像描述现在我想读取此文件并将这些 ASCII 转换为字符。 Finally I need to write these characters into another file.最后我需要将这些字符写入另一个文件。 How can I do that in java?我怎么能在java中做到这一点?

If the target encoding is UTF-8 , there is no point in writing a program;如果目标编码是UTF-8 ,则编写程序没有意义; the desired output file is identical to the input file.所需的输出文件与输入文件相同。

It was designed for backward compatibility with ASCII.它旨在向后兼容 ASCII。 Code points with lower numerical values, which tend to occur more frequently, are encoded using fewer bytes.具有较低数值的代码点,往往更频繁地出现,使用较少的字节进行编码。 The first 128 characters of Unicode, which correspond one-to-one with ASCII, are encoded using a single octet with the same binary value as ASCII, so that valid ASCII text is valid UTF-8-encoded Unicode as well. Unicode 的前 128 个字符与 ASCII 一一对应,使用与 ASCII 具有相同二进制值的单个八位字节进行编码,因此有效的 ASCII 文本也是有效的 UTF-8 编码的 Unicode。

Seperate each ASCII and insert each into an array.分离每个 ASCII 并将每个插入到一个数组中。

You can loop over each char using您可以使用循环遍历每个字符

Character.toString((char)yourASCIIchar);

This should produce the text representation of the ASCII.这应该产生 ASCII 的文本表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM