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

  • SEARCH
  • Home
  • 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 7803973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:45:38+00:00 2026-06-02T01:45:38+00:00

The following code prints [B@40545a60,[B@40545a60abc exp But I want to print abc , so

  • 0

The following code prints

[B@40545a60,[B@40545a60abc exp 

But I want to print abc, so that I can retrieve the correct message from the receiving system.

public class Operation {
InetAddress ip;
DatagramSocket dsock;
DatagramPacket pack1;
byte[] bin,bout;
WifyOperation(InetAddress Systemip)
{
    ip=Systemip;
    try {
        dsock=new DatagramSocket();

        } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

}

void sendbyte()
{
    String senddata="abc"; 
    bout=senddata.getBytes();
    pack1=new DatagramPacket(bout,bout.length,ip,3322);
    try {
        dsock.send(pack1);
        Log.d(pack1.getData().toString(),"abc exp");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

How can I retrieve string instead of byte from the packet pack1?

  • 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-02T01:45:40+00:00Added an answer on June 2, 2026 at 1:45 am

    New answer based on comment:

    Indeed, my old answer was incorrect.
    Update:

    String str = new String(
        pack1.getData(),
        pack1.getOffset(),
        pack1.getLength(),
        StandardCharsets.UTF_8 // or some other charset
    );
    

    Old answer:

    Do something like:

    byte[] data = pack1.getData();
    InputStreamReader input = new InputStreamReader(
        new ByteArrayInputStream(data), Charset.forName("UTF-8"));
    
    StringBuilder str = new StringBuilder();
    for (int value; (value = input.read()) != -1; )
        str.append((char) value);
    

    This assumes the byte data represents (just) UTF-8 text, which may not be the case.

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

Sidebar

Related Questions

The following code prints the message that I need it to print using the
The following code prints out 10 . How can I make it print out
The following code prints nothing CHECK_INCLUDE_FILE_CXX(glog/logging.h GLOG_INCLUDE) IF(GLOG_INCLUDE) MESSAGE(YY) ENDIF(GLOG_INCLUDE) But I have the
The following code prints: generic overload But what I wanted is that the overload
The following code prints '2' four times. Why does it never print '1'? Can
The following code, prints out Derived Base Base But I need every Derived object
I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))
The following code prints only A::A() , but no A::A(const A&) or operator= .
The following site Writing Boot Sector Code provides a sample of code that prints
The following code prints the desired output but it prints garbage at the end

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.