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.
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.
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.
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.
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.
Re: Created a Random Access File that saves gibberish to a text file
Quote:
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.
Quote:
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).