[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Converting a 4 bytes long to a java 8 bytes long...

I am reading a file that contains longs as 4 bytes, chars as 1 byte, ints as 2 bytes values..
I need to convert all the values to java native types.. (long as 8 byte, int as 4 byte and
char as 2 bytes)....

how can this be done...

can some code be included...
0
simlox
Asked:
simlox
  • 4
  • 2
1 Solution
 
mjenkinsCommented:
FileInputStream istream = new FileInputStream("t.tmp");
DataInputStream p2 = new DataInputStream(istream);
int i = p2.readInt(); // reads 4 byte value
int i1 = p2.readShort(); // reads 2 byte value
char c = (char)p2.readByte(); // reads 1 byte char
istream.close();

0
 
mjenkinsCommented:
Did this solve your problem?
0
 
simloxAuthor Commented:
Yes.. it worked perfectly..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mjenkinsCommented:
Then why did you give it a "D"? I'm curious. You must have expected more. I thought that the supplied code was sufficient an answer. Obviously I was mistaken.
0
 
simloxAuthor Commented:
I gave it a 'B'.... The other question on conversions
from a binary file using ObjectInputStream was given a
'D'..not this one.. I use the above information on the
same binary file..
0
 
mjenkinsCommented:
My mistake, I confused the questions. I'm still disappointed that you graded the other question a "D" .. It is kind of a matter of pride. Yours is the only D I've gotten thus far as an "expert" here. Oh, well...
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now