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

Thread: How can I add empty string ("") to the end of textfile

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default How can I add empty string ("") to the end of textfile

    I am writing to a RandomAccessFile. When I try to do raf.writeBytes("") the textfile ignores this empty string and just removes it from the file. Is there a way so that the textfile will save this empty character?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How can I add empty string ("") to the end of textfile

    It's kind of like trying to find your invisibility cloak after you've forgotten where you put it. How can you save something that doesn't exist to a file? What are you trying to do? Besides the obvious, because that doesn't seem possible to me.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: How can I add empty string ("") to the end of textfile

    This is a bit difficult to explain but I am writing a program that allows the user to write to a text file using randomaccessfile. The user enters name, age, and address, and each of these items is 20 bytes, so the record length is 60 bytes. When the user wants to search for a record, they input a record number, the program goes to seek(n*60), and those 60 bytes are stored into a byte array, and is then outputted. This works fine except for when the user wants the last record. I can't find a way to add extra space after the name,age,address to fill in the 60 bytes. I am getting the error java.io.EOFException: null due to this.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How can I add empty string ("") to the end of textfile

    Good explanation. You don't want to "pad" the records with nothing. That's not padding. Pick a padding character that you'd never expect to find in the name, age, and address fields. You could check an ASCII table and pick some bizarre character, or pick something simpler like '@' or '#' or whatever you'd like. Then you'll know to remove or ignore those characters that have been added at the end(s) of fields. I don't know if there's a standard padding character. You might search on that and see if there are any recommendations.

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    lordofrandom (October 17th, 2013)

  6. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: How can I add empty string ("") to the end of textfile

    Oh wow thats a good idea, I'll try that out thanks.

Similar Threads

  1. Understanding layers of system logic. Clarity for what "SDK" & "JDK" mean
    By MilkWetGhost in forum Java Theory & Questions
    Replies: 1
    Last Post: October 3rd, 2013, 12:25 PM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. How would you add a list of "events" and "tasks" to their respective arrays?
    By LIboy1027 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 19th, 2013, 06:32 AM
  4. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM

Tags for this Thread