9 Replies Latest reply: May 12, 2010 5:42 AM by EJP RSS

    Problem when reading binary data to ByteBuffer

    807580
      Hello,
      I'm trying to parse a dbf file. Usually it works fine, but for some files the first byte is not read properly. My code:
                FileChannel dbfFile=new FileInputStream(dbfFileName).getChannel();
                buffer=ByteBuffer.allocate(DBF_HEADER_SIZE_BASIC);
                   buffer.order(ByteOrder.LITTLE_ENDIAN);
                int count=dbfFile.read(buffer);
                buffer.flip();
                // read-in basic table definition
                buffer.position(0);
                dbfType=buffer.get();
      sometimes sets -125 to dbfType, but when I view the file with hex viewer the value is 83. How is it possible that the received value is negative? Is it my problem or java stream reading problem (feature?)?