Java Text File Write by Charset writeFile(String path, String content, Charset encoding)

Here you can find the source of writeFile(String path, String content, Charset encoding)

Description

write text to file

License

Apache License

Parameter

Parameter Description
path path to file
content content of file
encoding file encoding

Exception

Parameter Description
IOException an exception

Declaration

public static void writeFile(String path, String content, Charset encoding) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class Main {
    /**/*from   w w w .  j  a  va 2  s .c om*/
     * write text to file
     *
     * @param path
     *            path to file
     * @param content
     *            content of file
     * @param encoding
     *            file encoding
     *
     * @throws IOException
     */
    public static void writeFile(String path, String content, Charset encoding) throws IOException {
        Files.write(Paths.get(path), content.getBytes(encoding), StandardOpenOption.CREATE);
    }
}

Related

  1. writeAll(String data, OutputStream outputStream, Charset charset)
  2. writeContent(String content, String charset, File file)
  3. writeFile(File file, String content, Charset charset)
  4. writeFile(String content, File file, Charset encoding)
  5. writeFile(String path, String content, Charset charset)
  6. writeFile(String path, String output, Charset encoding)
  7. writer(OutputStream out, String charset)
  8. writer(String path, String content, String charset)
  9. writerBuffered(final File file, final Charset charset)