Java Text File Write by Charset write(Path path, Iterable lines, Charset cs, OpenOption... options)

Here you can find the source of write(Path path, Iterable lines, Charset cs, OpenOption... options)

Description

write

License

Open Source License

Declaration

public static Path write(Path path, Iterable<? extends CharSequence> lines, Charset cs, OpenOption... options) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;

import java.util.Arrays;

public class Main {
    public static Path write(Path path, Iterable<? extends CharSequence> lines, Charset cs, OpenOption... options) {
        try {//from   w w  w. j  ava 2  s  . c  o m
            return Files.write(path, lines, cs, options);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Path write(Path path, Iterable<? extends CharSequence> lines, OpenOption... options) {
        return write(path, lines, StandardCharsets.UTF_8, options);
    }

    public static Path write(Path path, String line, Charset cs, OpenOption... options) {
        try {
            return Files.write(path, Arrays.asList(line), cs, options);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Path write(Path path, String line, OpenOption... options) {
        return write(path, Arrays.asList(line), StandardCharsets.UTF_8, options);
    }

    public static Path write(Path path, byte[] bytes, OpenOption... options) {
        try {
            return Files.write(path, bytes, options);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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