[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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