Java Write String to File writeFile(String filename, String text)

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

Description

write File

License

Open Source License

Parameter

Parameter Description
filename a parameter
text a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static File writeFile(String filename, String text) throws IOException 

Method Source Code

//package com.java2s;
/**//  w  ww  .  j a v a  2s. c  om
 * Copyright (c) 2012-2013 by European Organization for Nuclear Research (CERN)
 * Author: Justin Salmon <jsalmon@cern.ch>
 *
 * XRootD is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * XRootD 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 Lesser General Public License
 * along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

public class Main {
    /**
     *
     * @param filename
     * @param text
     * @throws IOException
     */
    public static File writeFile(String filename, String text) throws IOException {
        FileOutputStream out = new FileOutputStream(filename);
        out.write(text.getBytes("UTF-8"));
        out.close();
        return new File(filename);
    }
}

Related

  1. writeFile(String filename, String s)
  2. writeFile(String fileName, String source)
  3. writeFile(String filename, String str)
  4. writeFile(String filename, String string)
  5. writeFile(String filename, String text)
  6. writeFile(String filename, String text)
  7. writeFile(String fileName, String text)
  8. writeFile(String filename, String text, boolean create)
  9. writeFile(String fileName, String text, String characterEncoding)