public void save() { BufferedWriter sourceFile = null; try { String sourceText = sourceArea.getText(); String cleanText = cleanupSource(sourceText); if (cleanText.length() != sourceText.length()) { sourceArea.setText(cleanText); String message = String.format( "One or more invalid characters at the end of the source file have been removed."); JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE); } sourceFile = new BufferedWriter(new FileWriter(sourcePath, false)); sourceFile.write(cleanText); setSourceChanged(false); setupMenus(); } catch (IOException ex) { ex.printStackTrace(); } finally { if (sourceFile != null) { try { sourceFile.close(); } catch (IOException ignore) { } } } }
private void jFileChooser1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jFileChooser1ActionPerformed if (!evt.getActionCommand().equals("CancelSelection")) { ysDir = jFileChooser1.getSelectedFile().toString(); File file = null; try { file = new File( new URL("file:/" + System.getProperty("user.dir") + "/addonsearch.cfg").toURI()); BufferedWriter output = new BufferedWriter(new FileWriter(file)); jFrame1.setSize(580, 420); jFrame1.setVisible(true); try { output.write("YSDIR =" + ysDir + "\nYSVERSION =" + versionBox.getText()); } finally { output.close(); } } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Cannot write to addonsearch config file!\n" + ex, "addonsearch", JOptionPane.ERROR_MESSAGE); } try { ys_cfg(file); } catch (Exception ex) { } } jFrame1.setVisible(false); } // GEN-LAST:event_jFileChooser1ActionPerformed
public void write(OutputStream os) throws Exception { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os)); String str = toString(); bw.write(str, 0, str.length()); bw.newLine(); bw.close(); }
public void save(String s, File f) { try { int saveNumber = 1; File file = new File(f.getAbsolutePath() + "/save.adv"); while (file.exists()) { file = new File(f.getAbsolutePath() + "/save" + saveNumber + ".adv"); saveNumber++; } file.createNewFile(); FileWriter fWriter = new FileWriter(file.getAbsoluteFile()); BufferedWriter bWriter = new BufferedWriter(fWriter); bWriter.write(s); bWriter.close(); } catch (IOException e) { e.printStackTrace(); } }
public void saveAs() { Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>(); if (fileExt.equals("m") || fileExt.equals("mac")) { filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)")); filters.add( new RopeFileFilter( new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)")); } else { filters.add( new RopeFileFilter( new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)")); filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)")); } filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)")); RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters); chooser.setDialogTitle("Save Source File"); String fileName = String.format("%s.%s", baseName, fileExt); chooser.setSelectedFile(new File(selectedPath, fileName)); JTextField field = chooser.getTextField(); field.setSelectionStart(0); field.setSelectionEnd(baseName.length()); File file = chooser.save(ROPE.mainFrame); if (file != null) { selectedPath = file.getParent(); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); writer.write(sourceArea.getText()); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (writer != null) { writer.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } }
public synchronized void runSuite() { SikuliIDE ide = SikuliIDE.getInstance(); if (fRunner != null) { fTestResult.stop(); showIDE(true); } else { try { showIDE(false); reset(); // get the current file's python code, write it to a temp file, and run it File tmpFile = null; String className = null; SikuliCodePane codePane = ide.getCurrentCodePane(); try { className = new File(ide.getCurrentFilename()).getName(); className = className.substring(0, className.lastIndexOf('.')); // remove extension tmpFile = File.createTempFile(className, ".py"); tmpFile.deleteOnExit(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF8")); codePane.writePython(bw); bw.close(); } catch (IOException e) { e.printStackTrace(); showIDE(true); } String filename = tmpFile.getAbsolutePath(); String path = ide.getCurrentBundlePath(); Test suite = genTestSuite(className, filename, path); doRun(suite); } catch (IOException e) { e.printStackTrace(); showIDE(true); } } }