I am trying to parse a file for an instance of a word in Java. The word is input from a JTextField. Depending on which selection is made in a JComboBox the filepath may change. The Text file contains names and their popularity. The desired output is how that name ranked for the year that is selected. I'm struggling with setting up an appropriate search. I have been able to get the file to open and output some of the contents of the file to the Java Console, but the file contains 1000 lines and I notice that the output in the console only begins with entry number 950 or so.
Here is what I have so far:
public void actionPerformed(ActionEvent e)
{
//Parse Input Fields
String name = inputArea.getText();
String genderSelected = genderList.getSelectedItem().toString();
String yearSelected = yearList.getSelectedItem().toString();
String yearFile = "Babynamesranking"+yearSelected+".txt";
try
{
File inputFile = new File(yearFile);
BufferedReader in = new BufferedReader(new FileReader(inputFile));
/**This is where I draw a blank and need help*/
in.close();
}
catch (IOException exception)
{
JOptionPane.showMessageDialog(null, "Error Reading File");
}
I have more work to do after I get this part working to display the results in the GUI and such, but that is easy and I can do that. Just struggling with how to get this part to work.
Example of text file we are parsing:
1 Jacob 22,507 Emma 18,765
2 Michael 20,524 Isabella 18,564
3 Ethan 20,174 Emily 17,397
4 Joshua 19,133 Olivia 17,030
5 Daniel 18,935 Ava 17,007
6 Alexander 18,639 Madison 16,985
7 Anthony 18,347 Sophia 16,042
8 William 18,337 Abigail 15,045
9 Christopher 17,876 Elizabeth 11,956
10 Matthew 17,526 Chloe 11,802
11 Jayden 17,088 Samantha 11,157
12 Andrew 16,711 Addison 10,742
13 Joseph 16,483 Natalie 10,179
14 David 16,246 Mia 10,156
15 Noah 15,748 Alexis 9,685