Java Text File Write by Charset writeStringToFile(String filename, String contents, Charset encoding)

Here you can find the source of writeStringToFile(String filename, String contents, Charset encoding)

Description

write String To File

License

Open Source License

Declaration

public static void writeStringToFile(String filename, String contents, Charset encoding) throws IOException 

Method Source Code


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

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;

public class Main {
    public static void writeStringToFile(String filename, String contents, Charset encoding) throws IOException {
        try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), encoding)) {
            out.write(contents);//from  w  w w. j  a va  2  s.c  o  m
        }
    }

    public static void writeStringToFile(File file, String contents, Charset encoding) throws IOException {
        try (Writer out = new OutputStreamWriter(new FileOutputStream(file), encoding)) {
            out.write(contents);
        }
    }
}

Related

  1. writeStreamToString(InputStream is, String charsetName)
  2. writeString(OutputStream os, String string, CharsetEncoder encoder)
  3. writeString(OutputStream out, String charset, String value)
  4. writeStringToFile(File file, String s, String charset)
  5. writeStringToFile(String fileContent, String filePath, String charset)
  6. writeStringToFile(String fileName, String str, String charset)
  7. writeStringToStream(String string, OutputStream stream, Charset charset)
  8. writeTextToFile(String textToWrite, String fileName, Charset cs)