//data type conversion
The basic types in Java are all signed types. The data obtained from the file read stream is a byte array. Some of these values are ASCII values greater than 127, so that the symbol bit goes wrong when converting to a char array, and the workaround: If the value is greater than 127 (that is, less than 0), add 256 to the value, thereby correcting the sign bit. The sample code is as follows:
Gets a byte array from string
int len = Str.length ();
byte[] ab = new Byte[len];
AB = Str.getbytes ();
for (int i=0; i<len; i++)
{
if (Ab[i] < 0)
System.out.print ((char) (ab[i]+256));
Else
System.out.print ((char) (ab[i]);
}
System.out.println ();
//About String.getbyte Error Resolution:
When you store ruby in string, some diacritics convert the error, and you can use the following method:
//gets the char array from string, processed to byte array
char[] AC = new char[8];
str.getchars (0, Len, AC, 0);
byte[] arrb = new Byte[len];
for (int i=0; i<len; i++)
{
arrb[i] = (byte) ac[i];
if (Arrb[i] < 0)
system.out.print ((char) (arrb[i]+256));
else
system.out.print ((char) (arrb[i]));
.}