I am trying to write the data that I take in via the JOptionPane to a Csv file. Is there a way that I can just write the whole class to it rather than doing it individually?? Cant seem to get it to work
import javax.swing.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class AddStudent implements Serializable
{
public static void main(String[] args) throws IOException
{
Student s1 = new Student();
String id = JOptionPane.showInputDialog(null, "Enter Students ID ");
s1.setStudentName(JOptionPane.showInputDialog(null, "Enter Students name "));
s1.setStudentNumber(JOptionPane.showInputDialog(null, "Enter Students ID "));
s1.setStudentEmail(JOptionPane.showInputDialog(null, "Enter Students Email Address "));
s1.setStudentAdd(JOptionPane.showInputDialog(null, "Enter Students Home Address "));
String ProgID = JOptionPane.showInputDialog(null, "Enter the Programme code the student is taking ") ;
FileWriter fw = new FileWriter("C:\\Users\\Packard Bell\\Desktop\\ProjectOOD\\ProgrammeID.csv", true);
}
FileOutputStream fos = new FileOutputStream("ProgrammeID");
ObjectOutputStream oos = new ObjectOutputStream(fos);
Student s1 = new Student();
oos.writeObject( s1);
oos.close();
}
And here is the Student Class
class Student
{
private String _studentNumber;
private String _studentName;
private String _studentAddress;
private String _studentEmail;
public void setStudentName(String studentName)
{
_studentName = studentName;
}
public void setStudentNumber(String studentNumber)
{
_studentNumber = studentNumber;
}
public void setStudentAdd(String studentAddress)
{
_studentAddress = studentAddress;
}
public void setStudentEmail(String studentEmail)
{
_studentEmail = studentEmail;
}
public String getNumber()
{
return _studentNumber;
}
public String getName()
{
return _studentName;
}
public String getAddress()
{
return _studentAddress;
}
public String getEmail()
{
return _studentAddress;
}
}