CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    Input double from the file

    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!


  2. #2
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    249

    Re: Input double from the file

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured