Here you can find the source of promptForFilename(String title)
public static File promptForFilename(String title)
//package com.java2s; import java.io.File; import javax.swing.JFileChooser; import javax.swing.JOptionPane; public class Main { /**// w w w . j a v a2s .c o m * Display the showSaveDialog which allows the user to specify file and * directory * * @return file to be saved */ public static File promptForFilename(String title) { File file = null; String _title = "Arrah Technology Save File"; if (title != null || "".equals(title) == false) _title = title; JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(_title); chooser.setCurrentDirectory(new File(".")); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } else { return null; } if (file.exists()) { int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) { return null; } } return file; } }