Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-08-07
6
Medium Priority
?
268 Views
Last Modified: 2010-05-18
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
Comment
Question by:simlox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
mjenkins earned 60 total points
ID: 1231715
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
 
LVL 3

Expert Comment

by:mjenkins
ID: 1231716
Did this solve your problem?
0
 

Author Comment

by:simlox
ID: 1231717
Yes.. it worked perfectly..
0
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.

 
LVL 3

Expert Comment

by:mjenkins
ID: 1231718
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
 

Author Comment

by:simlox
ID: 1231719
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
 
LVL 3

Expert Comment

by:mjenkins
ID: 1231720
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question