Java Utililty Methods Text File Write by Charset

List of utility methods to do Text File Write by Charset

Description

The list of methods to do Text File Write by Charset are organized into topic(s).

Method

voidcopy(byte[] input, Writer output, Charset charset)
copy
ByteArrayInputStream in = new ByteArrayInputStream(input);
copy(in, output, charset);
OutputStreamWritercreateWriter(@Nullable final OutputStream aOS, @Nonnull final Charset aCharset)
create Writer
return aOS == null ? null : new OutputStreamWriter(aOS, aCharset);
OutputStreamWritercreateWriter(@Nullable final OutputStream aOS, @Nonnull final String sCharset)
create Writer
try {
    return aOS == null ? null : new OutputStreamWriter(aOS, sCharset);
} catch (final UnsupportedEncodingException ex) {
    throw new IllegalArgumentException("Failed to create Writer for charset '" + sCharset + "'", ex);
PrintWritergetWriter(OutputStream os, String charset)
get Writer
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, Charset.forName(charset)));
return new PrintWriter(writer, true);
OutputStreamWritergetWriter(OutputStream out, String charsetName)
get Writer
return getWriter(out, Charset.forName(charsetName));
WritergetWriter(String fileName, Charset cs)
get Writer
OutputStreamWriter writer = null;
try {
    return new OutputStreamWriter(new FileOutputStream(fileName), cs);
} catch (FileNotFoundException e) {
    e.printStackTrace();
return writer;
BufferedWritergetWriter(String path, Charset encoding)
Returns a writer that uses the given encoding.
return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)), encoding));
PrintWriternewFilePrintWriter(File file, Charset charset)
new File Print Writer
return new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), charset));
BufferedWriternewWriter(File file, Charset charset)
new Writer
checkNotNull(file);
checkNotNull(charset);
return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset));
WriternewWriter(OutputStream output, Charset encoding)
Creates a java.io.Writer from an output stream
if (encoding != null) {
    return new OutputStreamWriter(output, encoding);
} else {
    return new OutputStreamWriter(output);