Check out example codes for "write data to a file GUI javafx". It will help you in understanding the concepts better.

Code Example 1

package com.fileio;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

 * @author mpawlan
public class FileIO extends Application {

    TextField textField;
    Label text, clicked;
    Button button, clickButton;
    BorderPane BPane;
    private boolean _clickMeMode = true;

    public void start (Stage primaryStage) { 
    //Create GridPane
    BPane = new BorderPane();
    BPane.setId("grid-pane   BPane.getStyleClass().add("pane-styles");

    //Create Scene and add Grid
    Scene Scene = new Scene(BPane, 300, 200);
    //Create the stage and add the scene
    primaryStage.setTitle("FileIO Application");

    text = new Label("Text to save to file:");
    textField = new TextField();
    button = new Button("Click Me");
    button.setOnAction(new EventHandler<ActionEvent>() {

    public void handle(ActionEvent event) {
        Object source = event.getSource();
        String s = null;
        //Variable to display text read from file
        if (_clickMeMode) {
            FileInputStream in = null;
            FileOutputStream out = null;
            try {
            //Code to write to file
            String text = textField.getText();
            byte b[] = text.getBytes();
            String outputFileName = System.getProperty("user.home",
            File.separatorChar + "home"
                + File.separatorChar + "monica")
                + File.separatorChar + "text.txt";
                out = new FileOutputStream(outputFileName);
                //Clear text field
                //Code to read from file
                String inputFileName = System.getProperty("user.home",
                    File.separatorChar + "home"
                    + File.separatorChar + "monica")
                    + File.separatorChar + "text.txt";
                File inputFile = new File(inputFileName);
                in = new FileInputStream(inputFile);
                byte bt[] = new byte[(int) inputFile.length()];
                s = new String(bt);
            } catch ( e) {
                    System.out.println("Cannotss text.txt");
            } finally {
                try {
                } catch ( e) {
            //Clear text field
            //Display text read from file
            text.setText("Text retrieved from file: \n\n" + s);
            button.setText("Click Again");
            _clickMeMode = false;
        } else {
            //Save text to file
            text.setText("Text to save to file:");
            button.setText("Click Me");
            _clickMeMode = true;

    //Set positions for each control in the BorderPane
    //Show the scene; 
    //main method
    public static void main(String[] args){

Learn ReactJs, React Native from