i am trying to write a program in java (on linux) using RandomAccessFile class for writing to files.
for some really weird reason it is not working. the most simplest code does not work. when try to use :
RandomAccessFile file = new RandomAccessFile("a.txt", "rw");
file.writeInt(3);
file.close();
it ether leaves the file blank or fills it with gibrish
i assume it has to do with some encoding issue i am not familiar with.
any one have any thoughts about it?
thank you
It simply writes a 32-bit integer to the file (in your case it is the bytes sequence 00 00 00 03). If you want to write it as a string, you need to
RandomAccessFile file = new RandomAccessFile("a.txt", "rw");
file.writeBytes(Integer.toString(3));
file.close();