/** * The ActionListener implementation * * @param event the event. */ public void actionPerformed(ActionEvent event) { String searchText = textField.getText().trim(); if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) { textPane.setText("Blank search text is not allowed for large IdTables."); } else { File outputFile = null; if (saveAs.isSelected()) { outputFile = chooser.getSelectedFile(); if (outputFile != null) { String name = outputFile.getName(); int k = name.lastIndexOf("."); if (k != -1) name = name.substring(0, k); name += ".txt"; File parent = outputFile.getAbsoluteFile().getParentFile(); outputFile = new File(parent, name); chooser.setSelectedFile(outputFile); } if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0); outputFile = chooser.getSelectedFile(); } textPane.setText(""); Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile); searcher.start(); } }
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(); } }