Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started