Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with method. This method is supposed to load a .txt file that is named test1.txt which already has info like so: 1 13233

need help with method. This method is supposed to load a .txt file that is named test1.txt which already has info like so:

1 13233 SIks 3209432 Heloo N

where the 1 indicates the row and 13233 is a String, Slks is a String, 320... is a String, and Heloo is a String and the method is supposed to read this file and store in obj called book for each row where there exists multiple rows of data like above.

public void loadData(String filename) { Scanner reader = null; try { reader = new Scanner(new File(filename)); Book book = null; // read until there are lines in the file while(reader.hasNextLine()) { book = new Book(reader.nextLine(), reader.nextLine(), reader.nextLine(), reader.nextLine(), Integer.parseInt(reader.nextLine())); reader.next(); // to escape the blank line in file booklist.add(book); } booklist.sort(null); // sorting the books reader.close(); } catch(IOException e) { System.out.print("Error! Unable to load the file. "); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

=+j Improve the effectiveness of global and virtual teams.

Answered: 1 week ago