Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws FileNotFoundException {
- Path movies = Paths.get("Movies.txt");
- ArrayList movieList = readMoviesFile(movies);
- for (int i = 0;i<movieList.size();i++){
- System.out.println(movieList.get(i));
- }
- }
- public static ArrayList<Video> readMoviesFile(Path txtFile){
- ArrayList<Video> returnList = new ArrayList<Video>();
- try (InputStream in = Files.newInputStream(txtFile);
- BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
- String line = null;
- while ((line = reader.readLine()) != null) {
- line = reader.readLine();
- String[] lineArray = line.split(";");
- int id = Integer.parseInt(lineArray[0]);
- String name = lineArray[1];
- String priceType = lineArray[2];
- boolean inStore;
- if (lineArray[3].equals("false")){
- inStore = false;
- }
- else{
- inStore = true;
- }
- returnList.add(new Video(id,name,priceType,inStore));
- }
- } catch (IOException e) {
- System.out.println("File not found!");
- }
- return returnList;
- }
- //Console
- Exception in thread "main" java.lang.NullPointerException
- at Run.readMoviesFile(Run.java:34)
- at Run.main(Run.java:17)
- //Movies.txt
- #Movie List - id,name,priceType,is in store
- 1;Matrix;OLD_PRICE;true
- 2;Movie43;BASIC_PRICE;true
- 3;Hobbit;NEW_PRICE;true
- 4;Silence of the Lambs;OLD_PRICE;false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement