Created
December 11, 2012 08:43
-
-
Save zachlatta/4257091 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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