I tried to create a text file named Employee.txt. It holds the details of the employees including their Employee ID, name, designation, department, address, and phone number. The text file contains the following code:
import java.io.*;
public class EmpDetails { public static void main(String args[]) { RandomAccessFile file=null; try { /* Opens the file in read/write mode */ file=new RandomAccessFile("Employee.txt","rw"); //code to write data to the file String s = "Employee ID " + “E001”+ " Employee Name" +”Steve” +"Designation" +”Accountant”; file.seek(file.length()); file.writeBytes(s); file.close(); } catch(IOException e) { System.out.println("Exception: " +e); }
The entries are not stored permanently to the storage device. What is the might be problem with the preceding code?