Java Text File Save writeFile(String text, File target)

Here you can find the source of writeFile(String text, File target)

Description

Writes a text file.

License

Open Source License

Parameter

Parameter Description
text the text
target the File to write

Return

the written File, or null if failed

Declaration

private static File writeFile(String text, File target) 

Method Source Code

//package com.java2s;
/*//from  w  w  w .jav  a 2s .  com
 * The tracker package defines a set of video/image analysis tools
 * built on the Open Source Physics framework by Wolfgang Christian.
 *
 * Copyright (c) 2018  Douglas Brown
 *
 * Tracker 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 3 of the License, or
 * (at your option) any later version.
 *
 * Tracker 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 Tracker; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA
 * or view the license online at <http://www.gnu.org/copyleft/gpl.html>
 *
 * For additional Tracker information and documentation, please see
 * <http://physlets.org/tracker/>.
 */

import java.io.File;
import java.io.FileWriter;

public class Main {
    /**
     * Writes a text file.
     * 
     * @param text the text
     * @param target the File to write
     * @return the written File, or null if failed
     */
    private static File writeFile(String text, File target) {
        try {
            FileWriter fout = new FileWriter(target);
            fout.write(text);
            fout.close();
            return target;
        } catch (Exception ex) {
        }
        return null;
    }
}

Related

  1. writeFile(String string, File location, boolean forceASCII)
  2. writeFile(String tailored, File f)
  3. writeFile(String targetPath, String filename, byte[] content)
  4. writeFile(String text, File file, boolean append)
  5. writeFile(String text, File outf)
  6. writeFile(String txt, File fyl)