- import java.io.UnsupportedEncodingException;
- public class tqc209 {
- public static void main(String[] args) throws UnsupportedEncodingException {
- String str="JAVA程式";
- String a=tohex(str);
- System.out.println(a);
- String toBig5=new String(str.getBytes("Big5"),"ISO8859_1");
- String b2hex=tohex(toBig5);
- System.out.println(b2hex);
- System.out.println(str);
- }
- private static String tohex(String str) {
- String rex="";
- char tmp;
- for(int i=0;i<str.length();i++){
- tmp=str.charAt(i);
- String t="0000"+Integer.toHexString(tmp);
- rex+=t.substring(t.length()-4)+" ";
- }
- return rex;
- }
- }
複製代碼 |