Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: RandomAccessFile.readByte() find EOF

  1. #1
    Member
    Join Date
    May 2010
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default RandomAccessFile.readByte() find EOF

    im trying to create a log file, for which i need to use the RandomAccessFile class for, its the only class i know of which can write a string to a file with 8 bits per char. problem is, the file pointer wants to stay at the beginning of the file. i need to move it manually with seek so that i can log more than one thing. i need to feed seek the length of the file, so i figured id read with RandomAccessFile.readByte() until i reach EOF. however, when readByte reaches EOF, an exception is thrown, which stops my program.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: RandomAccessFile.readByte() find EOF

    If you wish to just append to a file, use a FileWriter (most likely wrapped in a BufferedWriter), setting it to append to the parameter file. The file writing classes in Java need to be created in a unique way to deviate from 8bits/char ascii.
    Last edited by copeg; May 5th, 2010 at 08:26 PM.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: RandomAccessFile.readByte() find EOF

    Use This tutorial for encoding/decoding into different formats. You can then write out the values to the file using the FileWriter class as copeg said.

  4. #4
    Member
    Join Date
    May 2010
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RandomAccessFile.readByte() find EOF

    excellent! works great! ty!

Similar Threads

  1. how to find an element in an array
    By humdinger in forum Collections and Generics
    Replies: 8
    Last Post: April 9th, 2010, 05:22 PM
  2. cannot find symbol Error
    By bananasplitkids in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2010, 02:36 AM
  3. I can't find out what is wrong with my code. Please Help!
    By hallor618 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 10th, 2010, 02:44 PM
  4. where can i find the tmp/foo directory?
    By Idy in forum Java IDEs
    Replies: 11
    Last Post: January 19th, 2010, 11:21 AM
  5. [SOLVED] How to a set java class path?
    By captjade in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2009, 06:40 AM