Java JFileChooser exportFile(JFileChooser fileChooser, String contents)

Here you can find the source of exportFile(JFileChooser fileChooser, String contents)

Description

export File

License

Open Source License

Declaration

public static void exportFile(JFileChooser fileChooser, String contents) 

Method Source Code

//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());
            }
        }
    }
}

Related

  1. createJFileChooserWithOverwritePrompting()
  2. createOpenFileChooser(String title, String dir, Component parent, FileFilter filter)
  3. createReportFileChooser(String curDir, File defaultReportFile)
  4. createUserDefinedProfileFileChooser()
  5. directoryFetch(File starting)
  6. fileChooser()
  7. getChoiceFileFromUser()
  8. getDir(String title, String initDir, boolean allowFiles, Component parent)
  9. getDriveDisplayName(File path)