System.out.println(new String(new byte[]{ (byte)0x63 }, "US-ASCII"));
Note especially that converting bytes to Strings always involves an encoding. If you do not specify it, you'll be using the platform default encoding, which means the code can break when running in different environments.
Answer from Michael Borgwardt on Stack OverflowSystem.out.println(new String(new byte[]{ (byte)0x63 }, "US-ASCII"));
Note especially that converting bytes to Strings always involves an encoding. If you do not specify it, you'll be using the platform default encoding, which means the code can break when running in different environments.
The string ctor is suitable for this conversion:
System.out.println("string " + new String(new byte[] {0x63}));
How do you convert an "Byte array to string" text array back to normal text?
How To Convert A String To Byte()?
converting large byte array back to string
java - Convert string to byte array in frida js script - Reverse Engineering Stack Exchange
I got a string called abc, I got the bytes of abc and put them into the byte array named b, then i created a string which converts byte array b to string via Arrays.toString(b). This results in [97, 98, 99, 100, 101, 102, 103, 104, 105, 103, 104, 116].
How would you reverse this? (it's a seperate function).
So normally you can create a byte array as a variable something like
byte[] bytes = {69, 121, 101, ...};
but I have a huge one that blows up method/class file if I try this and wont compile. I've put it in a text file and trying to read it in, but now its coming as a string literal such as "69, 121, 101, ..."
if i try to use a readAllBytes method, its basically converting the above string to bytes which is now not matching and looks totally different like 49, 43, 101, .... so now its a byte array of a string-ified byte array if that makes sense.
i've managed to get it back to a byte array and then string, but it seems to be a janky way and wondering if theres a more proper way.
currently i'm
-
reading the whole string into memory
-
using string.split(",")
-
converting string value to int
-
converting int to byte
-
add to byte array
-
new String(myByteArray)
this works, but is it really the only way to do this?