Java FileOutputStream Create writeFileByChar(String content, String filename, String encoding)

Here you can find the source of writeFileByChar(String content, String filename, String encoding)

Description

write File By Char

License

Apache License

Declaration

public static void writeFileByChar(String content, String filename, String encoding) 

Method Source Code

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

import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStreamWriter;

import java.io.Writer;

public class Main {

    public static void writeFileByChar(String content, String filename, String encoding) {
        File file = new File(filename);
        Writer writer = null;// w w w  .  ja  va2 s. c om
        try {
            if (null == encoding || "".equals(encoding)) {
                writer = new OutputStreamWriter(new FileOutputStream(file));
            } else {
                writer = new OutputStreamWriter(new FileOutputStream(file), encoding);
            }
            writer.write(content);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
}

Related

  1. writeFileAsBytes(String fullPath, byte[] bytes)
  2. writeFileAsString(final File filePath, final String output, final String charset)
  3. writeFileAsString(String filename, String contents)
  4. writeFileBinary(String filename, byte[]... dataArrays)
  5. writeFileByBytes(String content, String filename)
  6. writeFileByLine(String content, String filename, boolean append)
  7. writeFileBytes(File pFile, byte[] pBytes)
  8. writeFileContent(String filepath, byte[] content)
  9. writeFileContent(String sFileName, byte[] content)