Home arrow static arrow Java Programming [Archive] - Do you have to read type (byte)
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Do you have to read type (byte)
This topic has 1 reply on 1 page.

Posts:343
Registered: 7/13/04
Do you have to read type (byte)  
Jul 19, 2004 4:01 PM



 
i want to read type (short) but not sure if i'm allowed to do that in java, do i always have to read type byte or can i read short? (what would be the other method that reads type short?)

DataInputStream in = new DataInputStream(new FileInputStream("c:/test.txt"));short[] data = new short[5]in.read(data);
 

Posts:37,103
Registered: 3/30/99
Re: Do you have to read type (byte)  
Jul 19, 2004 4:07 PM (reply 1 of 1)



 
Are you trying to read a Java short that was serialized? Or are you trying to read text that represents a short?

Make sure you understand the difference, it's very important.

If you open that text file and see something like

FFFF

or

-1

Then you want to read a string and parse it.

If it's a binary file that has a serialized short--i.e. you can't read a meaningful number with a text editor--then you'd want to use DataInputStream.readShort(). I don't know if what you've got will even compile, as I don't know if you can use a short[] where a byte[] is expected. If it does compile, I think you'll get one byte stuffed into each short. Not sure though, but I am pretty sure it's not what you want to be doing.
 
This topic has 1 reply on 1 page.