Skip to content

Instantly share code, notes, and snippets.

@zachlatta
Created December 11, 2012 08:43
Show Gist options
  • Save zachlatta/4257091 to your computer and use it in GitHub Desktop.
Save zachlatta/4257091 to your computer and use it in GitHub Desktop.
public static void loadBooks(ArrayList<Book> books, String fileName)
{
try(Scanner scanner = new Scanner(new File(fileName)))
{
String currentLine;
String delims = ", ";
String[] tokens;
scanner.useDelimiter(", ");
while(scanner.hasNext())
{
currentLine = scanner.nextLine();
tokens = currentLine.split(delims);
books.add(new Book(tokens[0], Double.parseDouble(tokens[1])));
}
}
catch(FileNotFoundException e)
{
JOptionPane.showMessageDialog(null, "Error opening BookPrices.txt! \n\nMake sure that it is in the same directory as the program.", "Inane error", JOptionPane.ERROR_MESSAGE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment