Here you can find the source of getSaveAsFile(String defaultName, String currentDirectory, String defaultExtension)
public static File getSaveAsFile(String defaultName, String currentDirectory, String defaultExtension)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.io.*; public class Main { protected static String gLastDirectory = System.getProperty("user.dir"); public static File getSaveAsFile(String defaultName, String currentDirectory, String defaultExtension) { String name = defaultName; if (defaultName == null) name = "data"; if (name.indexOf(".") == -1) name += "." + defaultExtension; if (currentDirectory == null) currentDirectory = System.getProperty("user.dir"); return getSaveAsFile(name, currentDirectory); }// w w w . j av a 2s . com public static File getSaveAsFile(String name, String currentDirectory) { if (currentDirectory == null) currentDirectory = gLastDirectory; JFileChooser fc = new JFileChooser(currentDirectory); File directory = new File(currentDirectory); File theFile = new File(directory, name); fc.setCurrentDirectory(directory); fc.setSelectedFile(theFile); fc.setDialogType(JFileChooser.SAVE_DIALOG); int ret = fc.showSaveDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); gLastDirectory = selectedFile.getParent(); return selectedFile; } else { return null; } } }