Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi so right now I have a file chooser in my controller class that should be working okay except for the last line(its just passing

Hi so right now I have a file chooser in my controller class that should be working okay except for the last line(its just passing null to the initialize class) so I am not sure how to pass the file as a String to the initialize method

public void openFile() throws IOException{ FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open Photo File"); fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("TEXT files (*.txt),(*.csv)", "*.txt", "*.csv")); File selectedFile = fileChooser.showOpenDialog(new Popup()); if(selectedFile !=null){ p.initialize(fileName); }

---------------------------------------------------------------

public void initialize(String fileName) { File file = new File(fileName); try { Scanner fin = new Scanner(file); while (fin.hasNextLine()) { lines.add(fin.nextLine()); } fin.close(); } catch (FileNotFoundException e) { System.out.println(file.getAbsolutePath() + " does not exists"); } }

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

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions