Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Book {
- private String ID;
- private String name;
- private int price;
- private String ISBN;
- private String authorfirstname;
- private String lastname;
- private String type;
- private int pages;
- public Book(String iD, String name, int price, String iSBN, String authorfirstname, String lastname, String type,
- int pages) {
- super();
- ID = iD;
- this.name = name;
- this.price = price;
- ISBN = iSBN;
- this.authorfirstname = authorfirstname;
- this.lastname = lastname;
- this.type = type;
- this.pages = pages;
- }
- public static void main(String[] args) throws FileNotFoundException {
- File text = new File("C:/temp/test.txt");
- ArrayList<Book> bookList = new ArrayList<Book>();
- // Creating Scanner instnace to read File in Java
- Scanner scnr = new Scanner(text);
- // Reading each line of file using Scanner class
- while (scnr.hasNextLine()) {
- String line = scnr.nextLine();
- String[] split = line.split(",");
- bookList.add(new Book(split[0], split[1], Integer.parseInt((split[2])), split[3], split[4], split[5],
- split[6], Integer.parseInt(split[7])));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement