title: How to read a text file into array list in Java?
body: <p>How can I can read my text file into the array list of
  Book type that shall be able to be modified in the program?</p>
  <p><em>[Edited]</em> I have edited my code to copy each string into one Book type. But it returns error as shown:</p>
  <blockquote>
  <p>Exception in thread &quot;main&quot; java.lang.NumberFormatException: For input string: &quot;eillance Valley&quot;</p>
  </blockquote>
  <p>May I know how to solve this?</p>
  <p>p.s. I am trying on GUI approach in my main class,
  just in case it matters.</p>
  <p>This is my text file (booklist.txt):</p>
  <pre><code>9781785785719,Surveillance Valley,Yasha Levine,Political Science,57.95,NONE
  9780241976630,How to Speak Machine,John Maeda,Non-Fiction,89.95,NONE
  9781119055808,R For Dummies,Andre De Vries,Design,107.77,NONE
  9780062018205,Predictably Irrational,Dan Ariely,Legal opinion,39.90,NONE
  9780008327613,The Globalist,John Waish,Non-Fiction,109.90,NONE
  9780525538349,Measure What Matters,John Doerr,Management,86.95,NONE
  9780807092156,Man's Search for Meaning,Viktor Frankl,Biography,49.90,NONE
  </code></pre>
  <p>This is my file-reading code:</p>
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  import java.io.*;
  
  public class FileReadDemo {
      public static void main(String[] args) {
          //ArrayList&lt;String&gt; arrayList = new ArrayList&lt;&gt;();
          ArrayList&lt;Book&gt; bookList = new ArrayList&lt;&gt;();
          
          try (Scanner s = new Scanner(new File(&quot;c:/Users/brightnow/Documents/booklist.txt&quot;)).useDelimiter(&quot;,&quot;)) {
             
              while (s.hasNext()) {
                  // bookList.add(s.next()); // does not work
                  //arrayList.add(s.nextLine());
                  String[] bookInfo = s.next().split(&quot;,&quot;);
                  
                  for (int i = 0; i &lt; bookInfo.length; i++) {
                      String ISBN = bookInfo[i].substring(0);
                      String title = bookInfo[i].substring(1);
                      String author = bookInfo[i].substring(2);
                      String genre = bookInfo[i].substring(3);
                      String price = bookInfo[i].substring(4);
                      String borrower = bookInfo[i].substring(5);
                      Double price2 = Double.parseDouble(price); // error here?
                      bookList.add(new Book(ISBN, title, author, genre, price2, borrower));
                  }
              }
          }
          catch (FileNotFoundException e) {
              // Handle the potential exception
          }
          
          // data are broke down into pieces?
          for(int i = 0; i &lt; bookList.size(); i++)
              System.out.println(bookList.get(i));
          
          // data showed as list with &quot;,&quot; as delimiter?
          System.out.println(bookList);
      }
  }
      
  
      
  </code></pre>
  <p>This is my Book type:</p>
  <pre><code>public class Book {
      private String ISBN;
      private String title;
      private String author;
      private String genre;
      private double price;
      private String borrower;
      
      public Book(String ISBN, String title, String author, String genre, Double price) {
          ISBN = this.ISBN;
          title = this.title;
          author = this.author;
          genre = this.genre;
          price = this.price;
          borrower = &quot;NONE&quot;; // set default no borrower
      }
      
      public String getISBN() {
          return ISBN;
      }
     
     public String getTitle() {
         return title;
     }
     
     public String getAuthor() {
         return author;
     }
     
     public String getGenre() {
         return genre;
     }
     
     public double getPrice() {
         return price;
     }
     
     public String getBorrower() {
         return borrower;
     }
     
     public void setISBN(String aISBN) {
         ISBN = aISBN;
     }
     
     public void setTitle(String aTitle) {
         title = aTitle;
     }
     
     public void setAuthor(String aAuthor) {
         author = aAuthor;
     }
     
     public void setGenre(String aGenre) {
         genre = aGenre;
     }
     
     public void setPrice(double aPrice) {
         price = aPrice;
     }
  
     public void setBorrower(String aBorrower) {
         borrower = aBorrower;
     }
     
  }
  
  </code></pre>