Advertisement
Guest User

Untitled

a guest
Jan 6th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public static void main(String[] args) throws FileNotFoundException {
  2. Path movies = Paths.get("Movies.txt");
  3.  
  4. ArrayList movieList = readMoviesFile(movies);
  5. for (int i = 0;i<movieList.size();i++){
  6. System.out.println(movieList.get(i));
  7. }
  8.  
  9.  
  10.  
  11. }
  12.  
  13. public static ArrayList<Video> readMoviesFile(Path txtFile){
  14. ArrayList<Video> returnList = new ArrayList<Video>();
  15. try (InputStream in = Files.newInputStream(txtFile);
  16. BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
  17.  
  18. String line = null;
  19. while ((line = reader.readLine()) != null) {
  20. line = reader.readLine();
  21. String[] lineArray = line.split(";");
  22. int id = Integer.parseInt(lineArray[0]);
  23. String name = lineArray[1];
  24. String priceType = lineArray[2];
  25. boolean inStore;
  26. if (lineArray[3].equals("false")){
  27. inStore = false;
  28. }
  29. else{
  30. inStore = true;
  31. }
  32. returnList.add(new Video(id,name,priceType,inStore));
  33. }
  34. } catch (IOException e) {
  35. System.out.println("File not found!");
  36. }
  37. return returnList;
  38. }
  39.  
  40.  
  41. //Console
  42. Exception in thread "main" java.lang.NullPointerException
  43. at Run.readMoviesFile(Run.java:34)
  44. at Run.main(Run.java:17)
  45.  
  46. //Movies.txt
  47. #Movie List - id,name,priceType,is in store
  48. 1;Matrix;OLD_PRICE;true
  49. 2;Movie43;BASIC_PRICE;true
  50. 3;Hobbit;NEW_PRICE;true
  51. 4;Silence of the Lambs;OLD_PRICE;false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement