Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class Book {
  7. private String ID;
  8. private String name;
  9. private int price;
  10. private String ISBN;
  11. private String authorfirstname;
  12. private String lastname;
  13. private String type;
  14. private int pages;
  15.  
  16. public Book(String iD, String name, int price, String iSBN, String authorfirstname, String lastname, String type,
  17. int pages) {
  18. super();
  19. ID = iD;
  20. this.name = name;
  21. this.price = price;
  22. ISBN = iSBN;
  23. this.authorfirstname = authorfirstname;
  24. this.lastname = lastname;
  25. this.type = type;
  26. this.pages = pages;
  27. }
  28.  
  29. public static void main(String[] args) throws FileNotFoundException {
  30. File text = new File("C:/temp/test.txt");
  31.  
  32. ArrayList<Book> bookList = new ArrayList<Book>();
  33. // Creating Scanner instnace to read File in Java
  34. Scanner scnr = new Scanner(text);
  35.  
  36. // Reading each line of file using Scanner class
  37. while (scnr.hasNextLine()) {
  38. String line = scnr.nextLine();
  39. String[] split = line.split(",");
  40. bookList.add(new Book(split[0], split[1], Integer.parseInt((split[2])), split[3], split[4], split[5],
  41. split[6], Integer.parseInt(split[7])));
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement