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 3 of 3

Thread: Creating a random access file

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Creating a random access file

    So....I want to create a random access file. The thing is, I know pretty much nothing about writing to files.

    What I do know is this:

    1. There are two ways to write to a file - PrintWriter and FileWriter.
    2. PrintWriter cannot append to a file; it can only overwrite the entire file.
    3. PrintWriter can format output ("printf"). This is necessary for a random access file because each field has to have the same length.
    4. FileWriter can append to a file by passing a boolean argument through its overloaded constructor.
    5. FileWriter cannot format the input (printf or writef do not exist).

    At least one of those is wrong, or else it would be impossible to create a random access file.

    So what's wrong there? And how do you make a random access file?


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating a random access file

    The String class has a format method that behaves exactly like the printf method.
    Improving the world one idiot at a time!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,405
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Creating a random access file

    how do you make a random access file?
    Use the RandomAccessFile class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Random access IO and printing to a laser printer
    By alan1 in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: March 12th, 2013, 12:15 AM
  2. Created a Random Access File that saves gibberish to a text file
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 21st, 2012, 11:45 AM
  3. Random Access File
    By Wish.. in forum Java Theory & Questions
    Replies: 2
    Last Post: March 12th, 2012, 02:40 PM
  4. Random Access File
    By silver_unicorn in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 12th, 2009, 01:51 AM
  5. Random Access File
    By silver_unicorn in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 10th, 2009, 10:44 PM