Saving the contents of a TextArea to a file Can this method be modified to be more efficient?

public void saveFile(File file, TextArea textArea) {
    if (file != null) {
        String filePath = file.getAbsolutePath();
        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath))) {
            writer.write(textArea.getText());
        } catch (IOException e) {
            System.out.println("savefile exception");
        }
    }
}
Some suggestion:


A "save to file" method without a valid file is useless. If the file is null your method is a no-op without a warning for the user.
Code reuse: your code works with TextArea only. A better solution would be a String argument instead of TextArea.
Method name: "saveFile" is too generic
Exception handling: you should catch the exception only if you know how to handle it or if you enrich the exception with new information before rethrow it


My version:

public void writeStringToFile(File file, String text) throws IOException {
    if (file == null)
        throw new IllegalArgumentException("file cannot be null");

    if (text == null)
        throw new IllegalArgumentException("text cannot be null");

    String filePath = file.getAbsolutePath();

    try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath))) {
        writer.write(text);
    }
}


But... DON'T REINVENT THE WHEEL!

A better solution is the Apache FileUtils class, see writeStringToFile method.

ps: English is not my mother tongue