storing and retreiving of text files using arraylist
please i am writin a program that accepts input and store in an array list so i can retrieve it any time i want but is seem not workin out.
am using PrintWriter and BufferedReader.
please i need ur help
thanks for ur help
here is my code
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class GUIIOTest extends JFrame implements ActionListener, Serializable
{
//declare an ArrayList collection object
ArrayList <Person> persons = new ArrayList<Person>();
JButton Storeb, Openb;
JTextField Namef, Genderf, Othersf;
JLabel Namel, Genderl, Othersl;
JComboBox Genderb;
Person p;
public GUIIOTest(){
Container cp = getContentPane();
setSize(200, 250);
setLocation(200, 173);
cp.setLayout(null);
Storeb = new JButton();
Storeb.setText("Store");
Storeb.setBounds(10, 180, 70, 20 );
Storeb.addActionListener(this);
cp.add(Storeb);
Openb = new JButton();
Openb.setText("Open");
Openb.setBounds(110, 180, 70, 20);
Openb.addActionListener(this);
cp.add(Openb);
Namef = new JTextField();
Namef.setBounds(53, 20, 120, 20);
Namef.setColumns(16);
cp.add(Namef);
//Genderf = new JTextField();
//Genderf.setBounds(53, 50, 30, 20);
//Genderf.setColumns(2);
String gender[] = {"", "M", "F"};
Genderb = new JComboBox(gender);
Genderb.setBounds(53, 50, 40, 20);
cp.add(Genderb);
Othersf = new JTextField();
Othersf .setBounds(53, 80, 50, 20);
Othersf.setColumns(10);
cp.add(Othersf);
Namel = new JLabel();
Namel.setBounds(6, 20, 50, 20);
Namel.setText("Name");
cp.add(Namel);
Genderl = new JLabel();
Genderl.setBounds(6, 50, 50, 20);
Genderl.setText("Gender");
cp.add(Genderl);
Othersl = new JLabel();
Othersl.setBounds(6, 80, 50, 20);
Othersl.setText("Others");
cp.add(Othersl);
}
public static void main(String [] args){
GUIIOTest Gframe = new GUIIOTest();
Gframe.setVisible(true);
Gframe.setTitle("IO Test");
Gframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ev){
if (ev.getSource() == Storeb ){
PrintWriter outStream = null;
try{
// Store
// File outFile = new File("Onwe.txt");
//FileOutputStream outFileStream = null;
//outFileStream = new FileOutputStream(outFile);
outStream = new PrintWriter(new FileOutputStream("Onwe.txt", true));
outStream.println(Namef.getText());
outStream.println();
outStream.println(Genderb.getSelectedItem());
outStream.println();
outStream.println(Othersf.getText());
outStream.println();
Namef.setText("");
Genderb.setSelectedIndex(0);
Othersf.setText("");
outStream.flush();
outStream.close();
}
catch(IOException e){
//JFrame frame = new JFrame("Error");
//frame.show();
//frame.setSize(120,170);
}
}
}
}

