Please help me correctly write the functions for reading data from a file into a TextArea, deleting data from it, as well as saving TextArea data to a file! Program Code:
package ch.makery.address.view; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; import javax.swing.JFileChooser; import ch.makery.address.MainApp; import ch.makery.address.PrepodMainApp; import ch.makery.address.model.GhurnalOcenok; import ch.makery.address.model.Lections; import ch.makery.address.model.Test; import javafx.beans.property.SimpleStringProperty; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.TextArea; public class LectionsController { @FXML public TextArea taLection; @FXML private Button butOpen;//save @FXML private Button butSave;//look @FXML private Button butUdalit;//udalit /** * The constructor. * The constructor is called before the initialize() method. */ public LectionsController() { } public void FileOpen(){ JFileChooser fileopen = new JFileChooser(); fileopen.setCurrentDirectory(new File(".")); int ret = fileopen.showDialog(null, "Открыть файл"); if (ret == JFileChooser.APPROVE_OPTION) { File file = fileopen.getSelectedFile(); try { FileRead(file.getAbsolutePath()); } catch (Exception e1) { } } } public void FileSave(){ JFileChooser fileopen = new JFileChooser(); fileopen.setCurrentDirectory(new File(".")); int ret = fileopen.showDialog(null, "Сохранить в файл"); if (ret == JFileChooser.APPROVE_OPTION) { File file = fileopen.getSelectedFile(); try { FileWrite(file.getAbsolutePath()); } catch (IOException e1) { } } } public void Delete(){ if(PrepodMainApp.getLectionList().size()>0){ taLection.clear(); } } public void FileWrite(String Filename)throws IOException{ FileWriter f = new FileWriter(Filename); for(Lections tst : PrepodMainApp.getLectionList()){ f.write(tst.Lecii.getValue() + "\r\n"); } f.close(); } public void FileRead(String Filename) throws FileNotFoundException, IOException{ PrepodMainApp.getLectionList().clear(); Scanner fin = new Scanner(new File(Filename)); String test; while(fin.hasNext()) { if(PrepodMainApp.getLectionList().size()>0){ fin.nextLine(); } test = fin.nextLine(); PrepodMainApp.getLectionList().add(new Lections( new SimpleStringProperty(test) )); } fin.close(); } } 