Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:13:12+00:00 2026-06-17T15:13:12+00:00

Possible Duplicate: Java Byte Array to String to Byte Array I have a method

  • 0

Possible Duplicate:
Java Byte Array to String to Byte Array

I have a method called READ() that accept a String parameter. This string is already have been converted into bytes. All I want is to convert into a readable string.

public static String READ(final String data) throws UnsupportedEncodingException{
   char[] temp = data.toCharArray();
   byte[] bytes = new byte[temp.length];
   int i = 0;
        
   for(char c : temp){
      bytes[i++] = (byte)c;
   }
        
   return new String(bytes, "UTF-8");
}

public static String SEND(String data) throws UnsupportedEncodingException{
   return data.getBytes()+"";
}

Testing:

String msg = "testing !";
String msgBytes = null;
   try {
        msgBytes = SEND(msg);
   } catch (UnsupportedEncodingException e2) {
        e2.printStackTrace();
   }
        
   System.out.println( "SEND: " + msgBytes);
   try {
         System.out.println("RECEIVE: " + READ(msgBytes));
   } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
   }

And the OUTPUT IS:

SEND: [B@452467ec

RECEIVE: [B@452467ec

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:13:14+00:00Added an answer on June 17, 2026 at 3:13 pm

    You print a byte[] which is an Object, so it just prints the reference into memory of that Object because that’s what the default implementation of toString() does.

    You should print the String directly. Don’t print its byte[] representation.

    What you do in your code is to transform a String into byte[] and then back to String in the wrong way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Converting any object to a byte array in java I have a
Possible Duplicate: Converting decimal to binary in Java I have found this code that
Possible Duplicate: Size of a byte in memory - Java I read this in
Possible Duplicate: Is Java pass-by-reference? if we have big byte[] array (like 40Mb) and
Possible Duplicate: Java: how to check that a string is parsable to a double?
Possible Duplicate: File to byte[] in Java I want to read data from file
Possible Duplicate: Java char array to int I have the following code, where stackCells
Possible Duplicate: Java 7 Date/Time API I've read rumors that Joda Time is slated
Possible Duplicate: In Java: How to zip file from byte[] array? Here's the deal,
Possible Duplicate: Byte array in objective-c Am converting some Java code to Objective-C and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.