+ 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!
4 Réponses
+ 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.
+ 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);
}
}
}
+ 2
Okay thanks to you all
0
you should write file text+=scan.nextline();