Java File Write nio writeFile(File file, String content)

Here you can find the source of writeFile(File file, String content)

Description

write File

License

Open Source License

Parameter

Parameter Description
file The file where the content will be stored, create a new file if it does not exist, the content will be written to the end of the file rather than the beginning
content The content

Exception

Parameter Description
IOException The exception to launch

Declaration

public static void writeFile(File file, String content) throws IOException 

Method Source Code


//package com.java2s;
/*//from   w w w  . ja  va2s  .c  om
 * 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 3 of the License, or
 * (at your option) 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, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.StandardOpenOption;

public class Main {
    /**
     *
     * @param file The file where the content will be stored, create a new file
     * if it does not exist, the content will be written to the end of the file
     * rather than the beginning
     * @param content The content
     * @throws IOException The exception to launch
     */
    public static void writeFile(File file, String content) throws IOException {
        Files.write(file.toPath(), content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND,
                StandardOpenOption.WRITE);
    }
}

Related

  1. writeFile(File file, String content)
  2. writeFile(File file, String text)
  3. writeFile(FileObject fileObject, String content)
  4. writeFile(List content, String targetFile)
  5. writeFile(OutputStream file, List data)