Java JFileChooser writeOnFile(String row)

Here you can find the source of writeOnFile(String row)

Description

write On File

License

Open Source License

Declaration

public static void writeOnFile(String row) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import javax.swing.JFileChooser;

public class Main {
    public static void writeOnFile(String file_name, String row) {
        File outFile = new File(file_name);
        FileWriter out;//from   w  ww . j  av a  2 s.  c  om
        try {
            out = new FileWriter(outFile, true);
            out.write(row);
            out.close();
        } catch (IOException e) {
        }
    }

    public static void writeOnFile(String row) {
        writeOnFile(getFileFromChooser().getAbsolutePath(), row);
    }

    public static File getFileFromChooser() {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("save as file");
        chooser.setSize(new java.awt.Dimension(45, 37)); // Generated
        //        chooser.setFileFilter(new FileNameExtensionFilter("png", "png"));
        File file = null;
        if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            file = chooser.getSelectedFile();
            return file;
        }
        return file;
    }

    public static File getFileFromChooser(String folderPath) {
        JFileChooser chooser = new JFileChooser(folderPath);
        chooser.setDialogTitle("save as file");
        chooser.setSize(new java.awt.Dimension(45, 37)); // Generated
        //        chooser.setFileFilter(new FileNameExtensionFilter("png", "png"));
        File file = null;
        if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            file = chooser.getSelectedFile();
            return file;
        }
        return file;
    }
}

Related

  1. setFileChooserFilters(JFileChooser fileDlg, String filters, int selectIndex)
  2. setSelectedFile(JFileChooser chooser, File file)
  3. SHOW_JFILECHOOSER(String title, String approvetext, int fileselectionmode, boolean multiselection)
  4. showFileChooserLoop(Component parentComponent, JFileChooser chooser)
  5. write(File file, String text)
  6. writeStringToFile(String output)