I have an array of bytes. I get a
string using US-ASCII encoding. Now I try to get the array of bytes from the resulting String using US-ASCII encoding. I expect the original array of bytes. However I am not getting it. Any clue? See the code below :
public class ByteToString
{
public static void main(String[] args)
{
try{
byte[] b = { -48 , -71 , -62 };
String s = new String( b, "US-ASCII");
System.out.println("String1 =" + s);
byte[] c = s.getBytes( "US-ASCII");
for( int i = 0 ; i < c.length ; ++i )
{
System.out.println( "C=" +c[i] );
}
}
catch( Exception e)
{
System.out.println( "error: " + e.getMessage() );
e.printStackTrace();
}
}
}