void (Project project, String fileName, String textToExport) { boolean append = false; File file = new File(fileName); if (file.exists()) { int result = Messages.showYesNoCancelDialog( project, IdeBundle.message("error.text.file.already.exists", fileName), IdeBundle.message("dialog.title.export.to.file"), IdeBundle.message("action.overwrite"), IdeBundle.message("action.append"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon() ); if (result != Messages.NO && result != Messages.YES) { return; } if (result == Messages.NO) { append = true; } } try (FileWriter writer = new FileWriter(fileName, StandardCharsets.UTF_8, append)) { writer.write(textToExport); } catch (IOException e) { Messages.showMessageDialog( project, IdeBundle.message("error.writing.to.file", fileName), CommonBundle.getErrorTitle(), Messages.getErrorIcon() ); } }