title: How do I write and delete Objects from a RandomAccessFile?
body: <p>I am currently working on a school project for which I need to save my data to a <code>RandomAccessFile</code>. I figured that this is by far not the most efficient way, but I have to do it. Note: I have to use the RandomAccessFile class.</p>
  
  <p>I understand how I can save simple <code>strings</code> and <code>int</code> created in the main method to a file, but I am having trouble transferring this knowledge onto my own program. </p>
  
  <p>I have 4 different classes, i.e. <code>Database</code>, <code>Group</code>, <code>Student</code>, <code>Rehearsal</code>. The <code>Database</code> class lets you add groups to a linked list of groups. To each group, you can then add students (see below) as well as rehearsal dates (its a theatre management program). These are added to <code>linkedlist&lt;Student&gt;</code> and <code>linkedlist&lt;Rehearsal&gt;</code> respectively.</p>
  
  <p>This is my <code>addStudent</code> method in the <code>Group</code> class that adds a student to the linkedlist of a  group that was created.</p>
  
  <pre><code>public void addStudent(int id, String firstname, String lastname) throws IOException {
      Student newstudent = new Student(id, firstname, lastname);
      if (!Students.contains(newstudent)) {
          Students.add(newstudent);
  } else 
          JOptionPane.showMessageDialog(null, "Student with ID " + id
                  + " already exists in group!", "Error",
                  JOptionPane.WARNING_MESSAGE);
  }
  </code></pre>
  
  <p>How do I let the method automatically write the student object to the file when it is executed? </p>
  
  <p>This is my <code>removeStudent</code> method:</p>
  
  <pre><code>public void removeStudent(int id) {
      if (!Students.remove(new Student(id, null, null))) {
          JOptionPane.showMessageDialog(null, "Student with ID[" + id
                  + "] not present. System unchanged.");
  
      } 
  }
  </code></pre>
  
  <p>Pretty much the same question, how can I then delete a specific object from the file when the method is executed. If you could me help me out on that as well, that would be great :)</p>