Click to See Complete Forum and Search --> : Input double from the file


May 6th, 2000, 01:26 AM
Hello,

Could someone tell me how to input double(or integer) type from a file?

I had used DataInputStream for that. When I used "writeInt" to write
to a file and then used "readInt" to read from the same file, it worked.
But if I used "readInt" directly to read from a .txt or .dat file, and then
used "System.out.println" to print out the value read in, the value is
extremely large or small(something like undefined). Such as if I have
8 single digit numbers in a file, after readInt(), I'll get maybe 5 large
numbers for the output.

Thanks a lot!

weaver
May 6th, 2000, 07:49 AM
You have a problem with the consistency of data types. In java, an int takes 4 bytes of memory to store. If you want to read each character in the file and get the numeric value of it, you should read the file in byte by byte and then convert them to a numeric value.

If you're reading a file that you've written in the course of a java program (via an OutputStream) then you can use a readInt() or readDouble() to get the apropriate data type into the program.

-------------------------------------------
weaver
icq# 64665116
Please rate this post.
http://weaver.x7.htmlplanet.com