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

Thread: Created a Random Access File that saves gibberish to a text file

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Created a Random Access File that saves gibberish to a text file

    File inputFile = new File(".../inputFile.txt");
    RandomAccessFile file = new RandomAccessFile(inputFile,"rw");
    file.seek(inputFile.length());
    file.writeDouble(randomInt);
    file.close();

    When I directly access the .../inputFile.txt file it is entirely gibberish. Is this a problem? If so, how do I fix it?

    Thanks in advance.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Created a Random Access File that saves gibberish to a text file

    Did you try reading the file using readDouble() and see if you get back what was written to the file?
    Did you read the API doc for the writeDouble() method so you would know what it writes out?
    What do you want to see in the file? If you want a String, use the method that writes a String.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Deprogrammer (September 21st, 2012)

  4. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Created a Random Access File that saves gibberish to a text file

    Thanks. At first, it seemed like a problem. But using readDouble it works as it should, I was just curious as to what was in the actual text file. Using String the text file is intelligible. Again, a nonissue, but thanks for your clarification.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Created a Random Access File that saves gibberish to a text file

    The binary representation of data can appear as gibberish. When you learn hexadecimal and read the file in a hex editor you will be able to make sense of that gibberish.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Created a Random Access File that saves gibberish to a text file

    I assumed it was something of that nature, but I do know it was not binary of hexadecimal as I am familiar with each. This is what went to the file:
    @@@@@@@@@@@h@@U@@WÄ@g@W@h@a@R@d‡@RÄ@e¿@c‡@h`@]@MÄ@U@@g†@
    I was about to start a new thread with another question, but since it related to this subject I will ask it here. How do I read the values in a Random Access File in sequence? I thought there would be an index like that of an array but it's not working out that way.

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Created a Random Access File that saves gibberish to a text file

    This is what went to the file:
    What are you using to view the binary content of the file? A text editor won't display its contents properly. You should use a hex editor to see what is in the file.

    How do I read the values in a Random Access File in sequence?
    Look at the API doc for the class. There are methods to specify where to start reading and how much to read (either explicitly or implicitly).
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    Deprogrammer (September 21st, 2012)

Similar Threads

  1. Random Access File
    By Wish.. in forum Java Theory & Questions
    Replies: 2
    Last Post: March 12th, 2012, 02:40 PM
  2. Accessing a random text file from within a folder?
    By RaustBD in forum Java Theory & Questions
    Replies: 1
    Last Post: November 29th, 2011, 01:13 PM
  3. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 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