Do the following until you have read all bytes. File should have even
bytes.
Assumption is that while writing the high byte was written before the
low byte. If it's not true exchange b0 and b1 in line 3 and 5 of the
code.
short s = 0;
byte b0 = in.read(); byte b1 = in.read();
s = s | b0;
s << 8;
s = s | b1;
Greg Stark - 28 Apr 2005 23:21 GMT
Also, consider using the DataInputStream class instead. Or perhaps
ByteBuffer might be more appropriate?
Rajesh.Rapaka - 29 Apr 2005 07:17 GMT
this what I did !! But somehow it wrked very differently!! I guess i'll
check my codes again.
regards,
Rajesh Rapaka
> HI all,
>
[quoted text clipped - 4 lines]
> contains of integer values ( in 16-bit). now using java how can i read
> the 16-bit signed integer value ??
Hmm Input. File. That might lead one to look in the java.io package.
java.io.DataInputStream
> A data input stream lets an application read primitive Java data
types > from an underlying input stream in a machine-independent way.
HTH.
BugBear
Lee Ryman - 29 Apr 2005 13:16 GMT
> Hmm Input. File. That might lead one to look in the java.io package.
>
> java.io.DataInputStream
Your not, are you? You couldn't actually be suggesting someone reads the
API documentation? Don't you know that is utter madness? Do you not
realise the consequences of encouraging people to start reading API
docs? The constant flux of stupid newsgroup questions stemming from the
lack of common-sense is critical not only to the necessary daily
expression of sarcasm and wit by gurus (required to maintain the
inflation of their heads), but for the stability of our universe and the
space-time continuum. It is people like you with outrages implication
such as the necessity to RTFM before posting that will lead to the
downfall of society, the destruction of Earth, the Big-Crunch, and (god
give me the courage to mention it) actually _good_ software!
bugbear - 29 Apr 2005 16:42 GMT
> Your not, are you? You couldn't actually be suggesting someone reads the
> API documentation? Don't you know that is utter madness? Do you not
[quoted text clipped - 7 lines]
> downfall of society, the destruction of Earth, the Big-Crunch, and (god
> give me the courage to mention it) actually _good_ software!
<<chuckle>>
BugBear