I
I
IgFil2019-06-26 13:16:21
Java
IgFil, 2019-06-26 13:16:21

Why is the file being created but it is empty?

package sample;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.stage.FileChooser;
import java.io.*;


public class Controller {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private TextArea text_area_main;

    @FXML
    private MenuItem openfile_btn;

    @FXML
    private MenuItem savefile_btn;

    @FXML
    void initialize() {
        assert text_area_main != null : "fx:id=\"text_area_main\" was not injected: check your FXML file 'sample.fxml'.";
        assert openfile_btn != null : "fx:id=\"openfile_btn\" was not injected: check your FXML file 'sample.fxml'.";
        assert savefile_btn != null : "fx:id=\"savefile_btn\" was not injected: check your FXML file 'sample.fxml'.";
        openfile_btn.setOnAction(event -> {

        });
        String output = text_area_main.getText();
        savefile_btn.setOnAction(event -> {
            FileChooser f = new FileChooser();
          File file =  f.showSaveDialog(null);

                try {
                FileWriter writer = new FileWriter(file);
                writer.write(output);
                }catch(IOException eq){eq.printStackTrace();}


        });
    }
}

the file appears when saving but it is empty

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-06-26
@NeiroNx

The file is opened for writing, but the procedure for writing to the file is not performed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question