does anyone know why this does not work?
public class AddStudentListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
//Changes title
Title.setText("Add Student");
//Obtians student information from the user
Object[] possibilities = {"IB Computer Science", "AP Computer Science", "Algebra II"};
StudentClass = (String)JOptionPane.showInputDialog(All, "What class is \nthe new student in?", "Info", JOptionPane.PLAIN_MESSAGE, null, possibilities, "IB Compter Science");
newStudent= (String)Messages.showInputDialog(All, "Please enter the full name\nof the new student.", "Info", JOptionPane.PLAIN_MESSAGE);
newGrade= (String)Messages.showInputDialog(All, "Please enter the grade\nof the new student.", "Info", JOptionPane.PLAIN_MESSAGE);
//Determines proper file to add information to
if (StudentClass.equals("IB Computer Science"))
{
ClassFile="CompSciIB.txt";
}
else if (StudentClass.equals("AP Computer Science"))
{
ClassFile="CompSciAP.txt";
}
else if (StudentClass.equals("Algebra II"))
{
ClassFile="AlgebraII.txt";
}
else
{
//assume student is in IB Computer Science, the teacher's most popular class
ClassFile="CompSciIB.txt";
}
//Writes the new information to the file
try
{
FileOutputStream WritingStream = new FileOutputStream(ClassFile);
PrintStream printer=new PrintStream(WritingStream);
printer.println(newStudent);
printer.println(newGrade);
WritingStream.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
I have the strings declared in other places. The program runs but does not write to the file when I check it. Also, does anyone know how to add to an existing file, not just write over it?