追加するテキストファイル内の特定のエントリを検索するにはどうすればよいですか?
データを入力するためのGUIを作成しましたが、ファイル全体を読み取ることはできますが、ユーザーの観点から、以前の予約を呼び出したい場合は無知だと考えているので、それは役に立ちません。そうする方法についての理解。データを読み戻すとき、オブジェクトをインスタンス化しようとしています。
ここに私のコードのいくつかがあります:
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());
}
}
});