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
Your problem is that String.getBytes() ... a byte array will return a useful result is incorrect. ... The object your method decompressGZIP() needs is a byte[]. So the basic, technical answer to the question you have asked is: byte[] b = string.getBytes(); byte[] b = string.getBytes(Charset.forName("UTF-8")); byte[] b = string.getBytes(StandardCharsets.UTF_8); // Java 7+ ... 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 - In Java, we can use new String(bytes, StandardCharsets.UTF_8) to convert a byte[] to a String. // string to byte[] byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8); // byte[] to string String s =
🌐
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 ...
🌐
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,
🌐
Techie Delight
techiedelight.com › home › java › convert a byte array to a string in java
Convert a byte array to a String in Java | Techie Delight
July 7, 2026 - 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 constructor.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › string-byte-array-java
String to byte array, byte array to String in Java | DigitalOcean
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
🌐
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
As you can see that Java API, particularly java.lang.String class provides methods and constructor that takes a byte[] and returns a String (or vice versa), but by default they rely on the platform's character encoding, which may not be correct, if the byte array is created from XML files, HTTP request data or from network protocols. You should always get the right encoding from the source itself. If you like to read more about what every programmer should know about String, you can check out this article.
🌐
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[] to String and String to byte[] in java – with examples. Conversion between byte array and string may be used in many cases including IO operations, generate secure hashes etc.
🌐
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.
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.

🌐
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); } } ...
🌐
Java67
java67.com › 2015 › 05 › how-to-convert-byte-array-to-string-in-java-example.html
How to Convert Byte array to String in Java with Example | Java67
Learn Java and Programming through ... array to String in Java but the most straightforward way is to use the String constructor which accepts a byte array i.e....
🌐
Attacomsian
attacomsian.com › blog › java-convert-byte-array-to-string
How to convert a byte array to a string in Java
October 29, 2022 - By default, new String() uses the platform default character encoding to convert the byte array to a string. If the character encoding is different, you can specify it by passing another argument to new String() as shown below: String str = ...
🌐
Scaler
scaler.com › home › topics › convert byte array to string in java
Convert Byte Array to String in Java - Scaler Topics
May 4, 2023 - But on the screen, we see many different characters, texts, images, etc. How is this possible? Character encoding is crucial for turning the byte array into a String. In plain English, byte values are numerical numbers, while character encoding is a map that assigns a certain character to a given byte.
🌐
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.
🌐
Medium
medium.com › @ujjawalr › convert-byte-to-string-in-5-ways-in-java-28271e01e6b8
Convert byte[] to String in 5 ways in java | by Ujjawal Rohra | Medium
February 12, 2023 - Java String class has a constructor which takes a byte[] as argument and returns its string representation. Example, byte[] bytes = {72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}; String str = new String(bytes); System.out.println(str); ...
🌐
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)
I need to convert it back into original string array.(Server runs on Tomcat using Servlets doPost method) Thanks in advance. Author @ http://www.ideasforideas.org/ Moody blogger who do not like to behave like target setting machines work. ... ByteArrayInputStream and ByteArrayOutputStream?
🌐
Java Code Geeks
javacodegeeks.com › home › core java
2 Examples to Convert Byte[] array to String in Java
September 3, 2014 - In this example, we have first * read an XML file with character encoding "UTF-8" into byte array and then created * String from that. When you don't specify a character encoding, Java uses * platform's default encoding, which may not be the same if file is a XML document coming from another system, emails, or plain text files fetched from an * HTTP server etc. You must first discover correct character encoding * and then use them while converting byte array to String.