Here you can find the source of showAndSaveReportFile(JFrame frmParent, File defaultReportFile, String data)
public static void showAndSaveReportFile(JFrame frmParent, File defaultReportFile, String data)
//package com.java2s; import java.io.*; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.filechooser.FileFilter; public class Main { public static void showAndSaveReportFile(JFrame frmParent, File defaultReportFile, String data) { JFileChooser fc = createReportFileChooser(defaultReportFile); int returnVal = fc.showSaveDialog(frmParent); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try { FileWriter writer = new FileWriter(file); writer.write(data);/* w w w. ja va2 s .c om*/ writer.flush(); writer.close(); JOptionPane.showMessageDialog(frmParent, "Save sucessfully!"); } catch (Exception ex) { ex.printStackTrace(); } } } public static JFileChooser createReportFileChooser(File defaultReportFile) { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { String filename = f.getName(); if (filename.endsWith(".html") || filename.endsWith(".htm") || filename.endsWith(".xhtml")) return true; return false; } @Override public String getDescription() { return "HTML file"; } }); if (defaultReportFile != null) fc.setSelectedFile(defaultReportFile); return fc; } }