File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Wanted to pack values  in java like struct.pack() in python Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Wanted to pack values  in java like struct.pack() in python" Watch "Wanted to pack values  in java like struct.pack() in python" New topic
Author

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

Muthu Kumaran Murugesan
Greenhorn

Joined: Jul 08, 2010
Posts: 2
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


Thanks & Regards
-
MK
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: Wanted to pack values in java like struct.pack() in python
 
Similar Threads
How to open .do file?
Is there a way in netbeans to include external libraries in project JAR file(s)?
How to package your solution for upload
Python's struct.pack in Java
how to get this same output format in java