|
-
May 12th, 2000, 09:43 AM
#1
Conversion from byte array to String and back
Hi, I'd be very grateful if somebody help.
I need to convert an array of bytes to a String, sending this string as a parameter and getting again a byte array.
The first step is acomplished through new String(byte[] myarray). Then I'm using getbytes() method.
This scheme works ok if bytes containing 0x8d, 0x8e, 0x8f, 0x90, 0x9d, 0x9e, are not involved. If it's not the case in my returned bytearray I obtain 0x3f.
Here is a demonstrating piece of code. Thanks.
javacode/
public static void main(String[] args) {
byte [] byteArray = new byte[256];
for (int i = 0; i < 256; i++) {
byteArray[i] = (byte)i;
}
String kk = new String(byteArray);
byte [] byteArray2 = kk.getBytes();
for (int j = 0; j < 256; j++) {
System.out.println(byteArray[j] + " = " + byteArray2[j]);
}
/javacode
-
February 14th, 2001, 05:19 AM
#2
Re: Conversion from byte array to String and back
Afraid I can't help you, but I've just hit exactly the same problem (also occurs with 0x81).
did you find a reason and/or a solution ?
-
February 14th, 2001, 06:41 AM
#3
Re: Conversion from byte array to String and back
Yes I've found a workaround to this problem: use the codepage ISO8859_1.
With the default codepage some values like 0x81 has no representation so you obtain the error. With the korean codepage every number you can obtain when obtaining a byte array from a string has representation so you can smoothly perform your string-byte-string tasks.
-
October 3rd, 2001, 03:52 PM
#4
Re: Conversion from byte array to String and back
How do I specify the codepage? I am using Visual Cafe 4.1.
Please advise. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|