Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 5th, 2004, 01:09 AM
Registered User
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading from Binary Files

Hi, I am trying to write java code to read and write to and from binary files. To write to a file I am using code like this:

    public void putUnsignedInt(int input) {
        Unsigned.putUnsignedInt ( _buffer, input );
    public void putUnsignedShort(short input) {
        Unsigned.putUnsignedShort( _buffer, input );
    public void putFloat(float input) {
        _buffer.putFloat( input );

Where the Unsigned class is from com.ronsoft.books.nio.buffers.Unsigned and _buffer is a ByteBuffer.

My problem is with reading the binary file. I am unable to read the floats or the ints. All I get is garbage values. I tried using the getFloat method of the ByteBuffer, the Unsigned get methods, and even messed around with shift operators, and still nothing. Can you tell me what the proper way is to read from the binary files? Or maybe tell me a method for reading and writing binary files that work together? I have been working on this for hours and I can't get anywhere. Any help would be greatly appreciated.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Text file in Binary mode for reading lawsoncobol Access VBA 1 August 3rd, 2006 04:01 AM
Reading field of 'Long' datatype from binary file peri C# 0 January 2nd, 2005 08:50 AM
Binary files MAXhYpe C# 0 November 2nd, 2004 04:42 AM
Differences between ASCII and Binary Files kuba C# 1 October 17th, 2004 07:22 PM
Reading from a text file and writing to a Binary 1 scott01 C++ Programming 0 July 28th, 2003 03:59 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.