Here you can find the source of getFileToSave(String description, String extension, Component component)
public static File getFileToSave(String description, String extension, Component component)
//package com.java2s; import java.awt.Component; import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; public class Main { public static File getFileToSave(String description, String extension, Component component) { JFileChooser fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter(description, new String[] { extension }); fileChooser.setFileFilter(filter); int action = fileChooser.showSaveDialog(component); if (action == JFileChooser.APPROVE_OPTION) { if (fileChooser.getSelectedFile() != null) { File theFile = fileChooser.getSelectedFile(); if (!theFile.getAbsolutePath().toLowerCase().endsWith("." + extension)) { theFile = new File(theFile.getAbsolutePath() + "." + extension); }/*from w w w .j ava 2 s. c om*/ return theFile; } } return null; } }