Java JFileChooser writeStringToFile(String output)

Here you can find the source of writeStringToFile(String output)

Description

write String To File

License

Open Source License

Declaration

public static void writeStringToFile(String output) 

Method Source Code

//package com.java2s;
/*/*  ww w  .j  av a2 s  .  c om*/
 * jadvisor/advisorui/FileUtility.java - Set of useful file utilities
 * Copyright (C) 2001-2002 Curtis Rawls
 * jadvisor.sourceforge.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.io.*;

import javax.swing.JFileChooser;

public class Main {
    public static void writeStringToFile(String output) {
        final JFileChooser fc = new JFileChooser();
        int returnVal = fc.showSaveDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
                BufferedWriter bwriter = new BufferedWriter(new FileWriter(fc.getSelectedFile()));
                bwriter.write(output, 0, output.length());
                bwriter.close();
            } catch (IOException e) {
                System.err.println("FileUtility (write): " + e.getMessage());
                //e.printStackTrace();
            }
        } else {
            System.out.println("Write command cancelled by user.");
        }
    }
}

Related

  1. setSelectedFile(JFileChooser chooser, File file)
  2. SHOW_JFILECHOOSER(String title, String approvetext, int fileselectionmode, boolean multiselection)
  3. showFileChooserLoop(Component parentComponent, JFileChooser chooser)
  4. write(File file, String text)
  5. writeOnFile(String row)