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"
呵呵,是不是很有趣。^_^ ~ _~ ...。。。。。。。。。今天你收穫了多少
,知識靠積累,朋友們,加油吧,總有一天,我們的知識會像金字塔。