Java Text File Write by Charset writeAll(Path path, String data, Charset cs)

Here you can find the source of writeAll(Path path, String data, Charset cs)

Description

write All

License

Apache License

Declaration

private static void writeAll(Path path, String data, Charset cs) throws IOException 

Method Source Code

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

import java.io.IOException;

import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import java.nio.file.Files;
import java.nio.file.Path;

import java.nio.file.StandardOpenOption;

public class Main {
    private static final Charset ENCODING_UTF8 = StandardCharsets.UTF_8;

    private static void writeAll(Path path, String data, Charset cs) throws IOException {
        try (OutputStream os = Files.newOutputStream(path, StandardOpenOption.CREATE,
                StandardOpenOption.TRUNCATE_EXISTING)) {
            os.write(data.getBytes(ENCODING_UTF8));
        }//from  ww w .j ava  2s .c  om
    }
}

Related

  1. write(final String s, final OutputStream out, Charset charset)
  2. write(Path file, CharBuffer data, Charset cs)
  3. write(Path path, Iterable lines, Charset cs, OpenOption... options)
  4. write(Path path, Iterable lines, Charset cs, OpenOption... options)
  5. write(String toWrite, File file, Charset charset)
  6. writeAll(String data, OutputStream outputStream, Charset charset)
  7. writeContent(String content, String charset, File file)
  8. writeFile(File file, String content, Charset charset)
  9. writeFile(String content, File file, Charset encoding)