Your byte array must have some encoding. The encoding cannot be ASCII if you've got negative values. Once you figure that out, you can convert a set of bytes to a String using:

byte[] bytes = {...}
String str = new String(bytes, StandardCharsets.UTF_8); // for UTF-8 encoding

There are a bunch of encodings you can use, look at the supported encodings in the Oracle javadocs.

Answer from omerkudat on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-byte-array-to-string
Java Program to Convert Byte Array to String - GeeksforGeeks
We can convert the byte array to String for the ASCII character set without even specifying the character encoding. The idea is to pass the byte[] to the string. It is as shown in the below example which is as follows: ... // Java Program to Convert Byte Array to String // Without character encoding // Importing required classes import java.io.IOException; import java.util.Arrays; // Main class class GFG { // Main driver method public static void main(String[] args) throws IOException { // Getting bytes from the custom input string // using getBytes() method and // storing it in a byte array byte[] bytes = "Geeksforgeeks".getBytes(); System.out.println(Arrays.toString(bytes)); // Creating a string from the byte array // without specifying character encoding String string = new String(bytes); // Printing the string System.out.println(string); } }
Published   July 23, 2025
Discussions

arrays - How to convert Java String into byte[]? - Stack Overflow
Is there any way to convert Java String to a byte[] (not the boxed Byte[])? More on stackoverflow.com
🌐 stackoverflow.com
How do you convert an "Byte array to string" text array back to normal text?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
7
4
February 24, 2021
Java Byte Array to String to Byte Array - Stack Overflow
To add to what is otherwise a correct (albeit incomplete) answer: 1) Any byte[] array being converted into a String in Java should specify the character-set. Is the byte[] array UTF-8 or something else? Not being specific or knowing what it is can create bugs. More on stackoverflow.com
🌐 stackoverflow.com
converting large byte array back to string
If you need it as String, why even have a byte array in the first place? Please, go into details of your use case and your reasoning for the byte array. This would probably help us. You could use a Scanner over the file and use nextByte with the delimiter set right to read in the values and directly throw them in the byte array. More on reddit.com
🌐 r/javahelp
12
2
August 21, 2025
🌐
Mkyong
mkyong.com › home › java › how to convert byte[] array to string in java
How to convert byte[] array to String in Java - Mkyong.com
January 18, 2022 - The correct way to convert byte[] to string is new String(bytes, StandardCharsets.UTF_8). ... package com.mkyong.string; import java.nio.charset.StandardCharsets; public class ConvertBytesToString2 { public static void main(String[] args) { ...
🌐
Crunchify
crunchify.com › java j2ee tutorials › in java how to convert byte[] array to string and string to byte[]?
In Java How to convert Byte[] Array To String and String to Byte[]? • Crunchify
December 28, 2025 - We will manipulate String and byte[] 5 different ways. ... toString() function on String object wont return actual string but only HashValue. Look for all comments mentioned in below Java program. package crunchify.com.tutorials; import ...
🌐
How to do in Java
howtodoinjava.com › home › java array › convert byte[] to string and vice-versa
Convert byte[] Array to String in Java - HowToDoInJava
December 15, 2022 - Learn to convert byte[] array to String and convert String to byte[] array in Java with examples.
🌐
Reddit
reddit.com › r/javahelp › how do you convert an "byte array to string" text array back to normal text?
r/javahelp on Reddit: How do you convert an "Byte array to string" text array back to normal text?
February 24, 2021 -

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).

Top answer
1 of 3
4
Try new String(b); This will convert it back to a regular string.
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Find elsewhere
🌐
Javatpoint
javatpoint.com › how-to-convert-byte-array-to-string-in-java
How to convert byte array to String in Java?
How to Convert byte Array to String in Java with oops, string, exceptions, multithreading, collections, jdbc, rmi, fundamentals, programs, swing, javafx, io streams, networking, sockets, classes, objects etc,
Top answer
1 of 12
286

You can't just take the returned string and construct a string from it... it's not a byte[] data type anymore, it's already a string; you need to parse it. For example :

String response = "[-47, 1, 16, 84, 2, 101, 110, 83, 111, 109, 101, 32, 78, 70, 67, 32, 68, 97, 116, 97]";      // response from the Python script

String[] byteValues = response.substring(1, response.length() - 1).split(",");
byte[] bytes = new byte[byteValues.length];

for (int i=0, len=bytes.length; i<len; i++) {
   bytes[i] = Byte.parseByte(byteValues[i].trim());     
}

String str = new String(bytes);

** EDIT **

You get an hint of your problem in your question, where you say "Whatever I seem to try I end up getting a byte array which looks as follows... [91, 45, ...", because 91 is the byte value for [, so [91, 45, ... is the byte array of the string "[-45, 1, 16, ..." string.

The method Arrays.toString() will return a String representation of the specified array; meaning that the returned value will not be a array anymore. For example :

byte[] b1 = new byte[] {97, 98, 99};

String s1 = Arrays.toString(b1);
String s2 = new String(b1);

System.out.println(s1);        // -> "[97, 98, 99]"
System.out.println(s2);        // -> "abc";

As you can see, s1 holds the string representation of the array b1, while s2 holds the string representation of the bytes contained in b1.

Now, in your problem, your server returns a string similar to s1, therefore to get the array representation back, you need the opposite constructor method. If s2.getBytes() is the opposite of new String(b1), you need to find the opposite of Arrays.toString(b1), thus the code I pasted in the first snippet of this answer.

2 of 12
140
String coolString = "cool string";

byte[] byteArray = coolString.getBytes();

String reconstitutedString = new String(byteArray);

System.out.println(reconstitutedString);

That outputs "cool string" to the console.

It's pretty darn easy.

🌐
Blogger
javarevisited.blogspot.com › 2014 › 08 › 2-examples-to-convert-byte-array-to-String-in-Java.html
2 Examples to Convert Byte[] Array to String in Java
June 27, 2025 - In this article, we will learn how to convert byte[] to String in Java both by using JDK API and with the help of Guava and Apache commons. There are multiple ways to change byte array to String in Java, you can either use methods from JDK, or you can use open-source complementary APIs like Apache commons and Google Guava.
🌐
Reddit
reddit.com › r/javahelp › converting large byte array back to string
r/javahelp on Reddit: converting large byte array back to string
August 21, 2025 -

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?

🌐
Delft Stack
delftstack.com › home › howto › java › how to convert byte array to string in java
How to Convert Byte Array to String in Java | Delft Stack
February 26, 2025 - This method provides more control over the character encoding and is suitable for larger byte arrays. import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.io.BufferedReader; byte[] byteArray = {72, 101, 108, 108, 111};
🌐
DigitalOcean
digitalocean.com › community › tutorials › string-byte-array-java
String to byte array, byte array to String in Java | DigitalOcean
August 3, 2022 - That’s why the output is the same for both the byte array to string conversion. String also has a constructor where we can provide byte array and Charset as an argument. So below code can also be used to convert byte array to String in Java.
🌐
Codeblogmoney
codeblogmoney.com › byte-array-to-string-in-java
Byte Array to String in Java - Code Blog Money
June 9, 2020 - Byte Array to String code 1 2 3 ... 66,108,111,103,32, 77,111,110,101,121}; //Convert byte[] to String String convertedToString = new String(byteArray); System.out.println("Byte Array to String : " + convertedToString); } } ...
🌐
Coderanch
coderanch.com › t › 446922 › java › convert-byte-array-string-array
How to convert byte array to string array ? (I/O and Streams forum at Coderanch)
From client side I am sending string array which by default get converted into byte array(client is in J2ME). On server side I receive the data in byte array format.
🌐
Centron
centron.de › startseite › string to byte array and byte array to string conversion in java
String to Byte Array and Byte Array to String Conversion in Java
February 5, 2025 - However if we provide Charset name, then we will have to either catch UnsupportedEncodingException exception or throw it. Better approach is to use StandardCharsets class introduced in Java 1.7 as shown below. ... That’s all the different ways to convert String to byte array in java.
🌐
Mkyong
mkyong.com › home › java › how to convert string to byte[] in java?
How to convert String to byte[] in Java? - Mkyong.com
January 17, 2022 - In Java, we can use new String(bytes, StandardCharsets.UTF_8) to convert byte[] to a String.
🌐
Coderanch
coderanch.com › t › 658180 › java › Converting-Byte-Array-String
Converting Byte Array to String (Java in General forum at Coderanch)
The constructor of the String class simply takes the byte array and copies it in binary to be treated as a string. No formatting is done. This is, of course, *not* what you want. You will need to loop through the six bytes, parse each byte to a two digit hexadecimal string, and add the delimiters ...
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › text › string.html
Byte Encodings and Strings (The Java™ Tutorials > Internationalization > Working with Text)
To create a String object from an array of non-Unicode bytes, invoke the String constructor with the encoding parameter.