Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    47
    Rep Power
    0

    Default Binary Confusion

    Hi all,

    I have a rather vexing problem. I am trying to read in a karel++ .wld (world) file which should be a list of integers stored in 32 bit big-endian format. So after I got this code running it is printing out numbers with decimals in them. How can this be? I tried attaching the world file but couldn't do it.

    /* FILE: ReadBinary.java */

    /* This program writes some Java primitive data types in their portable
    binary format.
    */
    import java.io.IOException;
    import java.io.DataInputStream;
    import java.io.FileInputStream;

    public class WorldReader{

    public static void main(String args[ ])
    {
    DataInputStream input = null;
    int count;
    String fileName = "Third.wld";

    // Open the file
    try {
    input = new DataInputStream(
    new FileInputStream(fileName));
    }
    catch (IOException e) {
    System.err.println("Unable to open file " + fileName +
    "\n" + e.toString( ));
    System.exit(1);
    }

    try{
    double value = input.readDouble( );
    System.out.println("Value read in: " + value);
    value = input.readDouble( );
    System.out.println("Value read in: " + value);
    }
    catch (IOException io) {
    System.err.println("Error during write to file " +
    fileName + "\n" + io.toString( ));
    System.exit(1);
    }
    try {
    input.close( );
    System.exit(0);
    }
    catch (IOException io) {
    System.err.println("Error closing file " +
    fileName + "\n" + io.toString( ));
    System.exit(1);
    }
    }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Binary Confusion

    If the file contains integers why are you reading the data in as doubles?

  3. #3
    Join Date
    Nov 2011
    Posts
    47
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 11-01-2011, 06:35 PM
  2. Java i/o confusion
    By willemien in forum New To Java
    Replies: 1
    Last Post: 02-11-2011, 02:35 PM
  3. object name confusion
    By mobosecomin in forum New To Java
    Replies: 4
    Last Post: 01-20-2011, 03:45 AM
  4. Confusion here @@' Help!
    By pleasurelyours in forum New To Java
    Replies: 7
    Last Post: 06-09-2010, 04:42 PM
  5. Tic Tac Toe confusion
    By jigglywiggly in forum New To Java
    Replies: 15
    Last Post: 04-12-2009, 02:47 AM

Posting Permissions

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