This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wanted to pack values in java like struct.pack() in python

 
Muthu Kumaran Murugesan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wanted to pack some values and later i have to unpack it ..
in python struct.pack() method is used to pack and unpack the values in the same way is there any way to pack values in java ,...??
If any suggestions kindly advice me
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I read it correctly, pack() turns the tuple into bytes and unpack() turns such bytes back into a tuple. Is this true?

If so, check out how serialization works. You can then write entire objects into any output stream using an ObjectOutputStream. To convert an object into bytes and back you can use the following:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!