Here you can find the source of exportFile(JFileChooser fileChooser, String contents)
public static void exportFile(JFileChooser fileChooser, String contents)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.io.*; public class Main { public static void exportFile(JFileChooser fileChooser, String contents) { int result = fileChooser.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { try { // Create file FileWriter fstream = new FileWriter(fileChooser .getSelectedFile().toString()); BufferedWriter out = new BufferedWriter(fstream); out.write(contents);// w ww. jav a 2 s .com //Close the output stream out.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } } } }