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+ only

However the problem you appear to be wrestling with is that this doesn't display very well. Calling toString() will just give you the default Object.toString() which is the class name + memory address. In your result [B@38ee9f13, the [B means byte[] and 38ee9f13 is the memory address, separated by an @.

For display purposes you can use:

Arrays.toString(bytes);

But this will just display as a sequence of comma-separated integers, which may or may not be what you want.

To get a readable String back from a byte[], use:

String string = new String(byte[] bytes, Charset charset);

The reason the Charset version is favoured, is that all String objects in Java are stored internally as UTF-16. When converting to a byte[] you will get a different breakdown of bytes for the given glyphs of that String, depending upon the chosen charset.

Answer from Stewart on Stack Overflow
๐ŸŒ
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 - To convert a byte array to String, you can use String class constructor with byte[] as the constructor argument. byte[] bytes = "hello world".getBytes(); String s = new String(bytes); Since Java 8, we have Base64 class available.
Discussions

java - How to convert byte array to string and vice versa? - Stack Overflow
I have to convert a byte array to string in Android, but my byte array contains negative values. If I convert that string again to byte array, values I am getting are different from original 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
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
Writing an object to S3 from a (java) string or bytestream which contains multi-glyph emoji truncates the output.
This input:

๐Ÿ‘จ๐Ÿฟ ๐Ÿ‘จ ๐Ÿ™๐Ÿผโ€โ™€๏ธ

Produces a file which I can't open because IntelliJ can't work out the encoding but Notepad++ reads it as:

๐Ÿ‘จ๐Ÿฟ๐Ÿ‘จ๐Ÿ™ If I tell Notepad++ that it is UTF-8.

More on reddit.com
๐ŸŒ r/aws
3
0
March 20, 2023
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ convert string to byte array and reverse in java
Convert String to Byte Array and Reverse in Java | Baeldung
March 17, 2024 - How to convert a byte[] to an InputStream using plain Java or Guava. ... First, weโ€™ll look at various ways to convert a String to a byte array.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ string-byte-array-java
String to byte array, byte array to String in Java | DigitalOcean
August 3, 2022 - We can use String class getBytes() method to encode the string into a sequence of bytes using the platformโ€™s default charset. This method is overloaded and we can also pass Charset as argument. Here is a simple program showing how to convert String to byte array in java.
๐ŸŒ
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.
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,
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ convert-byte-to-string-in-java
Convert byte to String in Java
January 15, 2025 - Then we're getting string representation of byte variables using toString() method and then result is printed. package com.tutorialspoint; public class ByteDemo { public static void main(String[] args) { // create 2 Byte objects b1, b2 Byte ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-convert-byte-array-to-string
Java Program to Convert Byte Array to String - GeeksforGeeks
It is as shown in the below example ... args) throws IOException { // Getting bytes from the custom input string // using getBytes() method and // storing it in a byte array byte[] bytes = "Geeksforgeeks".getBytes(); ...
Published ย  July 23, 2025
๐ŸŒ
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 - $ cd java-string ยท How to create Zip file in Java ยท How to convert byte arrays to String in Java ยท Java 11 โ€“ String JavaDoc ยท Wikipedia โ€“ UTF-8 ยท Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-a-byte-value-to-string-value-in-java-with-examples
How to Convert a Byte value to String value in Java with Examples - GeeksforGeeks
July 12, 2025 - Below is the implementation of ... // Convert byte value to String value // using + operator method String stringValue = "" + byteValue; return (stringValue); } // Driver code public static void main(String[] args) { // The byte ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java-program-to-convert-byte-to-string
Java Program to convert byte to string
In Java, there are different ways to convert byte to string. Using toString() method, you can easily convert byte to string as shown below โˆ’ Example
๐ŸŒ
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.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 394963 โ€บ java โ€บ convert-byte-String
how to convert byte [] to String? (Beginning Java forum at Coderanch)
November 20, 2003 - Use String string = new String(buffer); This will convert the bytes into characters according to the platform's default encoding; in the us-english locale, this is UTF-8, so one byte is one character.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 396604 โ€บ java โ€บ Convert-byte-string
Convert byte to string (Beginning Java forum at Coderanch)
I have been able to get it to work using the String.valueOf, but the resulting string contains the ASCII representation of the character. I have tried all combinations of converting the in[0] to a string variable z and can not get any of them to compile. Is there a simple way to do this? ... I got this to work by using the following code; The byte (in[]) is the character rectived.
๐ŸŒ
JA-VA Code
java-performance.info โ€บ home โ€บ byte to string in java: mastering conversion methods
Converting Byte to String Java: A Comprehensive Guide
September 27, 2023 - To address these issues and improve the efficiency of byte-to-string conversions, consider the following alternatives: Specify Character Encoding: Instead of relying on the default platform encoding, specify a character encoding explicitly when constructing the string. This ensures consistency across platforms; Use Charset: Utilize the `Charset` class and its `decode` method to convert bytes to characters efficiently.
๐ŸŒ
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
Here is our sample program to show why relying on default character encoding is a bad idea and why you must use character encoding while converting byte array to String in Java. In this program, we are using Apache Commons IOUtils class to directly read files into a byte array.
๐ŸŒ
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?

๐ŸŒ
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....