native2ascii命令的一种用法

native2ascii命令的一种用法!

在JDK文件中这样描述这个命令的:

native2ascii Convert text to Unicode Latin-1.

语法如下:

native2ascii [options] [inputfile [outputfile]]

具体的选项有:

-reverse

Perform. the reverse operation: convert a file with Latin-1 and/or

Unicode encoded characters to one with native-encoded characters.

-encoding encoding_name

Specify the encoding name which is used by the conversion procedure.

The default encoding is taken from System property file.encoding. The

encoding_name string must be taken from the first column of the table of

supported encodings in the Supported Encodings document.

-Joption

Pass option to the Java virtual machine, where option is one of the

options described on the reference page for the java application launcher.

For example, -J-Xms48m sets the startup memory to 48 megabytes

有时当我们反编译别人的代码的时候,会看到这样的代码句子,

System.out.println(“ConnectionPool–/u521D/u59CB/u5316/u6570/u636E/u5E93/u5

F02/u5E38==>>” + exception.toString());

当然这里只是一个简单的打印出错信息的句子,我们可以用native2ascii命令将它转换成原本的中文的。

做法如下:如有个文件名叫:Test.class.先用反编译工具将其反编译,我用的是DJ Java Jecompiler,反编译后的文件扩展名为:”.jad”

import java.io.PrintStream;public class Test{    public static void main(String args[])    {        String s = "/u770B/u770B/u6211/u6D4B/u8BD5/u7684/u6548/u679C/uFF01";        System.out.println((new StringBuilder()).append("/u5475/u5475/uFF1A").append(s).toString());    }}

这是反编译后的文件。

反编译后会有一个相应的文件产生。可能扩展名不会直接是”.java”,没关系,直接将反编译好的文件扩展名改为.java,如我这里,改为test.java。然后开启DOS,然后进入到相应的目录:如下:

J:/>

J:/>dir

2004-11-11 10:10 588 Test.jad

J:/>

将Test.jad改名为Test.java,然后用如下命令:

J:/>native2ascii -reverse -encoding gb2312 Test.java Test_gb2312.java

结合上面讲的这个命令的几个选项来看,这里用到了两个选项:

-reverse 和 -encoding ,-encoding的后面是指定要转换成的编码。我要将其显示为中文,所以我选用了gb2312,Test.java是刚才反编译后改名的文件,Test_gb2312.java就是转码过后的代码,用editplus打开看看Test_gb2312.java文件,会发现中文显示出来了,这就转码成功了,这个命令你用过了吗?

呵呵,在命令行还可以实时转码,打开DOS输入native2ascii命令,回车,然后会有光标在闪,千万不要以为程序没执行完,光标闪是在等待你输入字符,切换到中文输入状态,输入,“java我爱你”后回车,会看到这样显示:“java/u6211/u7231/u4f60″

呵呵,是不是很有趣。^_^ ~ _~ …。。。。。。。。。今天你收获了多少,知识靠积累,朋友们,加油吧,总有一天,我们的知识会像金字塔。

命运掌握在自己手中

native2ascii命令的一种用法

相关文章:

你感兴趣的文章:

标签云: