Results 1 to 3 of 3
Thread: Binary Confusion
- 12-01-2011, 04:05 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 47
- Rep Power
- 0
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);
}
}
}
- 12-01-2011, 04:11 AM #2
Re: Binary Confusion
If the file contains integers why are you reading the data in as doubles?
- 12-01-2011, 04:17 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 47
- Rep Power
- 0
Similar Threads
-
Convert integer to binary then each binary character to boolean
By davidfla90 in forum New To JavaReplies: 1Last Post: 11-01-2011, 05:35 PM -
Java i/o confusion
By willemien in forum New To JavaReplies: 1Last Post: 02-11-2011, 01:35 PM -
object name confusion
By mobosecomin in forum New To JavaReplies: 4Last Post: 01-20-2011, 02:45 AM -
Confusion here @@' Help!
By pleasurelyours in forum New To JavaReplies: 7Last Post: 06-09-2010, 03:42 PM -
Tic Tac Toe confusion
By jigglywiggly in forum New To JavaReplies: 15Last Post: 04-12-2009, 01:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks