服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

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"

呵呵,是不是很有趣。^_^         ~ _~ ...。。。。。。。。。今天你收获了多少

,知识靠积累,朋友们,加油吧,总有一天,我们的知识会像金字塔。

扫描关注微信公众号