I have a simple text file that I am reading the contents of in a GUI. It's a simple program that enables a user to browse the file and add to it if needed. I have this part running fine, but I'm having some difficulty reading just the first word of the first line and the first word of the last line.
Basically if I have a text file like this:
California, West, 1981, 115, 25.99
New York, East, 1991, 120, 19.95
I want to be able to call the first word of the first line (California) and the first word of the last line (New York). Any suggestions for making this happen? Thanks a bunch!
Here's my code:
String line = "";
FileReader fWriter = null;
BufferedReader writer = null;
try {
fWriter = new FileReader("info.txt");
writer = new BufferedReader(fWriter);
List<String> list = new ArrayList<String>();
while((line = FileReader.readLine())!= null){
list.add(line);
}
list.get(0); // first line
list.get(list.size()-1); // last line
} catch (Exception e) {
}