我有一个以下格式的文本,即CP037格式,我希望将其转换为Java中的十六进制格式。
Text1-AGNSAöÃÃÃÃõµjÂqÂÂà Text2-AGNS的tµ.nÂZ |ÂÃ
首先,我想到了将其转换为ascii,然后转换为十六进制的方法,但是转换没有正确进行
public class CP037ToASCII {
public static String Tex (String ascii)
{
String hex = "";
for (int i = 0; i < ascii.length(); i++)
{
char ch = ascii.charAt(i);
int in = (int)ch;
String part = Integer.toHexString(in);
hex += part;
}
System.out.println(hex);
return hex;
}
public static String Tex (String ascii)
{
String hex = "";
for (int i = 0; i < ascii.length(); i++)
{
char ch = ascii.charAt(i);
int in = (int)ch;
String part = Integer.toHexString(in);
hex += part;
}
return hex;
}
public static void main (String[] args) throws java.lang.Exception
{
String encodedStr = "AGNSAñA¦ûÃÃÂõÂjÂq  Ã";
byte[] ebcByte = encodedStr.getBytes("Cp037");
System.out.println("EBCDIC Byte " + ebcByte);
String ascStr = new String(ebcByte, "ASCII");
System.out.println("ASCII String " + ascStr);
System.out.println ("String converted to hexadecimal");
Tex(ascStr);
System.out.println ("String converted to hexadecimal");
System.out.println (Tex("AGNSA??A???????????j?q???? ? ?"));
}
}
could anyone please help