I'm confused how can I save my data for example I hava (Student ID , Name , Surname) the only Student ID is Integer, I want save these data to text file when I Press (AddButtton) and then I want to update these data when I press (UpdateButton),the data are saved but I'm used Vector Array each time when the data saved the brackets are appear in the file and when press the (UpdateButton) the data aren't return to my TextField to update.
class BtnListenerAdd implements ActionListener{
public void actionPerformed(ActionEvent a) {
if (a.getSource()==btnAdd){
Student s=new Student(tfname.getText(),tfsurname.getText());
s.number=Integer.parseInt(tfno.getText());
myVector.add(s);
//System.out.println(s);
try{
java.io.RandomAccessFile raf =
new java.io.RandomAccessFile("e:\\random.txt", "rw");
for (int i = 0; i < myVector.size(); i++) {
raf.writeChars(myVector.toString());
}
raf.seek(0);
while (raf.getFilePointer() < raf.length()) {
System.out.println(raf.readChar());
}
raf.close();
}catch(Exception e){
System.out.println( e.toString() );
}
}
if (a.getSource()==btnList){
ta1.setText("");
for (Student s : myVector) {
ta1.append(s.toString()+ "\n");
}
}
}
}
class BtnListenerUpdate implements ActionListener{
public void actionPerformed(ActionEvent s) {
if (s.getSource()==btnUpdate){
Student l=new Student(tfname.getText(),tfsurname.getText());
l.number=Integer.parseInt(tfno.getText());
myVector.add(l);
try{
java.io.RandomAccessFile raf =
new java.io.RandomAccessFile("e:\\random.txt", "rw");
for(int i=0; i <myVector.size(); i++) {
raf.writeChar(myVector.size());
}
raf.seek(0);
int no= raf.readInt();
tfno.setText(no + "");
System.out.println(no);
String nam = "";
for(int x=0; x<50; x++){
nam += raf.readChar();
}
nam = "";
for(int x=0; x<50; x++){
nam += raf.readChar();
}
}catch(Exception e){
System.out.println( e.toString() );
}
}
}
}