+ 3

JTextArea() and File()

I'm working on a project that can save and open a text file. Now the save section is perfect but the problem is the opening aspect of it where when file selected only the last line of the text in the text-file will be written into the JTextArea. Please help me! Please!

3rd May 2020, 1:23 PM
BAYODE BLESSING AKINBOLA
4 odpowiedzi
+ 2
BAYODE BLESSING AKINBOLA Maybe this works (found on Stackoverflow): FileReader reader = new FileReader("yourFile.txt); yourTextArea.read(reader, "yourFile.txt"); Otherwise please show us your code.
3rd May 2020, 1:33 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
I am using JFileChooser for the importing of file. Here is the Opening method: public void TheOpener() throws Exception{ JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); Scanner scan = new Scanner(file); int i =1; while (i>=1 && scan.hasNext()) { fileText = scan.nextLine(); System.out.println(fileText); } } }
3rd May 2020, 3:55 PM
BAYODE BLESSING AKINBOLA
+ 2
Okay thanks to you all
11th May 2020, 7:47 AM
BAYODE BLESSING AKINBOLA
0
you should write file text+=scan.nextline();
4th May 2020, 3:47 AM
Khaled Abd Al-hamead Hawwas
Khaled Abd Al-hamead Hawwas - avatar