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 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) { } } } }
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(); } } } }
/** Creates new form addonSearch */ public addonSearch() { initComponents(); ys = new listener(); try { logfileURL = new URL("file:/" + System.getProperty("user.dir") + "/addonsearch.htm"); log = new File(logfileURL.toURI()); log.delete(); log = new File(logfileURL.toURI()); log_out = new BufferedWriter(new FileWriter(log, true)); log_out.write(""); refresh(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Cannot create logfile for chat window." + " Try running this program in 'My Documents'.\n" + ex, "addonsearch", JOptionPane.ERROR_MESSAGE); } File file = null; BufferedWriter output; try { file = new File(new URL("file:/" + System.getProperty("user.dir") + "/addonsearch.cfg").toURI()); if (file.exists()) ys_cfg(file); else { output = new BufferedWriter(new FileWriter(file)); jFrame1.setSize(580, 420); jFrame1.setVisible(true); } } catch (Exception ex) { if (!ex.toString().equals("java.io.IOException: Stream closed")) System.out.println(ex); // JOptionPane.showMessageDialog(this, "Impossible to read the YSChat config file!\n"+ex, // "YS_chat", JOptionPane.ERROR_MESSAGE); } makeLocalDB(); messOut.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } } }); }
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); } } }
public static void refresh() throws IOException { log_out.flush(); Document doc = messOut.getDocument(); doc.putProperty(Document.StreamDescriptionProperty, null); messOut.setPage(logfileURL); }