List of usage examples for java.nio.file Files newBufferedWriter
public static BufferedWriter newBufferedWriter(Path path, Charset cs, OpenOption... options) throws IOException
From source file:com.rvantwisk.cnctools.controllers.CNCToolsController.java
@FXML public void onViewGCode(ActionEvent actionEvent) { try {//from w ww .ja v a 2 s . c o m if (v_projectList.getSelectionModel().selectedItemProperty().get() != null) { final Project p = v_projectList.getSelectionModel().selectedItemProperty().get(); if (p.postProcessorProperty().get() == null) { MonologFX dialog = new MonologFX(MonologFX.Type.QUESTION); dialog.setTitleText("No postprocessor"); dialog.setMessage("No post processor configured, please select a post processor first!"); dialog.show(); } else { File file = File.createTempFile("cnctools", "gcode"); final GCodeCollection gCode = p.getGCode(toolDBManager); file.createNewFile(); file.deleteOnExit(); if (file != null) { try (BufferedWriter br = Files.newBufferedWriter(file.toPath(), Charset.forName("UTF-8"), new OpenOption[] { StandardOpenOption.WRITE })) { br.write(gCode.concate().toString()); br.write("\n"); br.flush(); br.close(); Project project = projectModel.projectsProperty() .get(v_projectList.getSelectionModel().getSelectedIndex()); showGCodeFromFile(project, file.getAbsolutePath()); } catch (IOException ex) { handleException(ex); } } } } } catch (Exception e) { handleException(e); } }