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.
Here is the code I use to write to the file:
while(!done){
junk.seek(y);
System.out.println("Enter name.");
junk.writeBytes(sc.nextLine());
y+=20;
System.out.println("Enter age.");
junk.seek(y);
junk.writeBytes(sc.nextLine());
y+=20;
System.out.println("Enter city.");
junk.seek(y);
junk.writeBytes(sc.nextLine());
y+=20;
System.out.println("Are you done?(Y/N)");
choice = sc.nextLine();
if(choice.equalsIgnoreCase("Y")){
done = true;
}
So basically how can I add extra empty space after the last item in the textfile?