Search:

Type: Posts; User: Norm

Search: Search took 0.18 seconds.

  1. Replies
    28
    Views
    4,569

    Re: Reading a files header, hex

    The code in post #20 reads bytes from the file into an int variable and tests if that variable has a -1 value. The statements need to be changed around to be used in a for loop instead of a while...
  2. Replies
    28
    Views
    4,569

    Re: Reading a files header, hex

    From post #20

    fis.read() // reads a byte from file
  3. Replies
    28
    Views
    4,569

    Re: Reading a files header, hex

    Inside the loop are these 3 steps:
    read next byte
    if byte is -1 quit -> the file is too short
    print the byte


    if (i != -1) {
    The loop control varialbe: i will never be -1. It will count...
  4. Replies
    28
    Views
    4,569

    Re: Reading a file and comparing them to an array to get the file type - java

    Post the code with the for loop that won't work.

    The steps the code should take for step 1:
    loop 4 times
    read next byte
    if byte is -1 quit -> the file is too short
    print the byte
    end loop
  5. Replies
    28
    Views
    4,569

    Re: Reading a file and comparing them to an array to get the file type - java

    The advice is the same as the last 3 or 4 times: use a for loop to read the first 4 bytes from the file.
    Get rid of the while() loop!

    Try writing the method in several steps:
    1) write a loop to...
  6. Replies
    28
    Views
    4,569

    Re: Reading a file and comparing them to an array to get the file type - java

    That should be a small method that reads the first few bytes of a file and returns them.



    Same answer as above.

    Where is the small method you have been working on to do this? All the code...
  7. Replies
    28
    Views
    4,569

    Re: Editing this code so that it takes a file instead of a string

    Do you know how to write a for loop that will loop 4 times? Try using that kind of a loop to read and reformat the bytes that are read from the file instead of a while loop that goes until the end...
  8. Replies
    28
    Views
    4,569

    Re: Editing this code so that it takes a file instead of a string

    Where is the for loop?
  9. Replies
    28
    Views
    4,569

    Re: Editing this code so that it takes a file instead of a string

    Can you isolate the code like the code in post#3 and post it here?
  10. Replies
    28
    Views
    4,569

    Re: Editing this code so that it takes a file instead of a string

    Please post the code and explain what the problem with it was.
  11. Replies
    28
    Views
    4,569

    Re: Editing this code so that it takes a file instead of a string

    Please explain what problem you are having? What does: from a directory" mean?
    Are you having problems getting the path to the folder that contains the file?
    Do you want the user to select it? ...
  12. Replies
    28
    Views
    4,569

    Re: Reading a files header, hex

    If a while loop that reads to the end of the file works for all the bytes in a file, replacing the while loop with a for loop can limit the number of bytes read and displayed.
  13. Replies
    28
    Views
    4,569

    Re: Reading a files header, hex

    Change the while loop to a for loop that loops 4 times.

    Please edit your post and wrap your code with


    <YOUR CODE HERE>

    to get highlighting and preserve formatting.
  14. Replies
    28
    Views
    4,569

    Re: Reading a files header, hex

    It should be easy to stop reading on any given byte. Can you explain what the problem is with limiting the number of bytes read and displayed?
Results 1 to 14 of 14