I have a byte array, that I need to write to txt-file. After that I need to read that byte array from there and here appears a problem. I read this Convert Java string to byte array But it works only with positive numbers. Here what I have
public static void main(String args[]) throws UnsupportedEncodingException
{
byte [] a= new byte [2];
a[0]=15;
a[1]=-2;
String line = new String(a, "UTF-8");
byte[] b = line.getBytes();
System.out.println(b[0]);
System.out.println(b[1]);
}
and result is
15
63
toString()
doesn't work as well.
Thank you in advance for help.