How do I search for a specific entry in a text file that I append to?
I made a GUI to input the data in to, however I can read the whole file, but that is of no use to me as I am thinking from a Users perspective that if an earlier booking wants to be called on I am clueless on the understanding on how to do so. When I read the data back I am trying to instantiate an object.
Here some of my code:
search.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String booking;
String where;
booking = JOptionPane.showInputDialog(" Booking Reference: ");
System.out.println("Booking Reference " + e.getActionCommand());
if (booking.equals("Wales"))
try{
FileInputStream fstream = new FileInputStream("Wales.txt");
// Use DataInputStream to read binary NOT text.
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
while ((strLine = br.readLine()) != null) {
System.out.println (strLine);
}
in.close();
}
catch (Exception ex)
{
System.err.println("Error: " + ex.getMessage());
}
else if (booking.equals("Scotland"))
try{
FileInputStream fstream = new FileInputStream("Scotland.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
System.out.println (strLine);
}
where = JOptionPane.showInputDialog("Which booking reference do you wish to search?: ");
}
catch (Exception ex)
{
System.err.println("Error: " + ex.getMessage());
}
}
});