Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    To see how to use the FileInputStream's read() method, read the API doc. One of the overloads for read has a byte array and number of bytes to read.
    f(data == jpgSOI)
    Both of those to be compared are arrays. The == test will be to see if the two variables point to the same array.
    To test if the contents of the arrays are equal, you'll have to find/write a method to compare them element by element.
    Perhaps the Arrays class has a method.

  2. #22
    playwin2 is offline Member
    Join Date
    Aug 2008
    Posts
    58
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    To see how to use the FileInputStream's read() method, read the API doc. One of the overloads for read has a byte array and number of bytes to read.
    Maybe you are suggesting this method?
    read(data, 0, <length I want>);// data is byte[] data;

    No it won't do. :(

    Quote Originally Posted by Norm View Post
    Both of those to be compared are arrays. The == test will be to see if the two variables point to the same array.
    To test if the contents of the arrays are equal, you'll have to find/write a method to compare them element by element.
    Perhaps the Arrays class has a method.
    Ah! I see, thanks :)

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    it won't do
    Don't understand why.

  4. #24
    playwin2 is offline Member
    Join Date
    Aug 2008
    Posts
    58
    Rep Power
    0

    Default

    If I use byte and assign a value 0xFF (which is 255 in dec) then it got translated to -1 (System.out.print() ), so I objected on using byte, but later I saw that the write() method however writing the correct value when writing to the file.

    So it seems I can use bytes after all, however I'm still not able to print right value on console.

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    I'm still not able to print right value on console.
    Again, can you show an example?
    Is it a problem with the sign bit being propagated?
    If you assign a value to an int and the value has its sign bit set, the sign will be spread. AND the int with 0XFF for a byte or 0xFFFF for a short value to clear the spread sign bits.

  6. #26
    playwin2 is offline Member
    Join Date
    Aug 2008
    Posts
    58
    Rep Power
    0

    Default

    Thanks forum (specially at Norm) the problem is solved. :)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. work on byte image in j2me
    By sunitikumar in forum CLDC and MIDP
    Replies: 0
    Last Post: 07-24-2008, 05:12 PM
  2. using Byte arrays
    By mew in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 04:54 AM
  3. BufferedImage to Byte
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 09:17 PM
  4. int to byte
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 08:22 PM
  5. Replies: 0
    Last Post: 01-08-2008, 06:29 PM

Posting Permissions

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