public class FileWriterWithEncoding extends ProxyWriter
This class provides a simple alternative to FileWriter that allows an encoding to be set. Unfortunately, it cannot subclass FileWriter.
By default, the file will be overwritten, but this may be changed to append.
The encoding must be specified using either the name of the Charset, the Charset, or a CharsetEncoder. If the default encoding is
required then use the FileWriter directly, rather than this implementation.
| Modifier and Type | Class and Description |
|---|---|
static class |
FileWriterWithEncoding.Builder
Builds a new
FileWriterWithEncoding instance. |
out| Constructor and Description |
|---|
FileWriterWithEncoding(File file,
Charset charset)
Deprecated.
Use
builder() |
FileWriterWithEncoding(File file,
Charset encoding,
boolean append)
Deprecated.
Use
builder() |
FileWriterWithEncoding(File file,
CharsetEncoder charsetEncoder)
Deprecated.
Use
builder() |
FileWriterWithEncoding(File file,
CharsetEncoder charsetEncoder,
boolean append)
Deprecated.
Use
builder() |
FileWriterWithEncoding(File file,
String charsetName)
Deprecated.
Use
builder() |
FileWriterWithEncoding(File file,
String charsetName,
boolean append)
Deprecated.
Use
builder() |
FileWriterWithEncoding(String fileName,
Charset charset)
Deprecated.
Use
builder() |
FileWriterWithEncoding(String fileName,
Charset charset,
boolean append)
Deprecated.
Use
builder() |
FileWriterWithEncoding(String fileName,
CharsetEncoder encoding)
Deprecated.
Use
builder() |
FileWriterWithEncoding(String fileName,
CharsetEncoder charsetEncoder,
boolean append)
Deprecated.
Use
builder() |
FileWriterWithEncoding(String fileName,
String charsetName)
Deprecated.
Use
builder() |
FileWriterWithEncoding(String fileName,
String charsetName,
boolean append)
Deprecated.
Use
builder() |
| Modifier and Type | Method and Description |
|---|---|
static FileWriterWithEncoding.Builder |
builder()
Constructs a new
FileWriterWithEncoding.Builder. |
afterWrite, append, append, append, beforeWrite, close, flush, handleIOException, write, write, write, write, write@Deprecated public FileWriterWithEncoding(File file, Charset charset) throws IOException
builder()file - the file to write to, not nullcharset - the encoding to use, not nullNullPointerException - if the file or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(File file, Charset encoding, boolean append) throws IOException
builder()file - the file to write to, not null.encoding - the name of the requested charset, null uses the default Charset.append - true if content should be appended, false to overwrite.NullPointerException - if the file is null.IOException - in case of an I/O error.@Deprecated public FileWriterWithEncoding(File file, CharsetEncoder charsetEncoder) throws IOException
builder()file - the file to write to, not nullcharsetEncoder - the encoding to use, not nullNullPointerException - if the file or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(File file, CharsetEncoder charsetEncoder, boolean append) throws IOException
builder()file - the file to write to, not null.charsetEncoder - the encoding to use, null uses the default Charset.append - true if content should be appended, false to overwrite.NullPointerException - if the file is null.IOException - in case of an I/O error.@Deprecated public FileWriterWithEncoding(File file, String charsetName) throws IOException
builder()file - the file to write to, not nullcharsetName - the name of the requested charset, not nullNullPointerException - if the file or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(File file, String charsetName, boolean append) throws IOException
builder()file - the file to write to, not null.charsetName - the name of the requested charset, null uses the default Charset.append - true if content should be appended, false to overwrite.NullPointerException - if the file is null.IOException - in case of an I/O error.@Deprecated public FileWriterWithEncoding(String fileName, Charset charset) throws IOException
builder()fileName - the name of the file to write to, not nullcharset - the charset to use, not nullNullPointerException - if the file name or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(String fileName, Charset charset, boolean append) throws IOException
builder()fileName - the name of the file to write to, not nullcharset - the encoding to use, not nullappend - true if content should be appended, false to overwriteNullPointerException - if the file name or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(String fileName, CharsetEncoder encoding) throws IOException
builder()fileName - the name of the file to write to, not nullencoding - the encoding to use, not nullNullPointerException - if the file name or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(String fileName, CharsetEncoder charsetEncoder, boolean append) throws IOException
builder()fileName - the name of the file to write to, not nullcharsetEncoder - the encoding to use, not nullappend - true if content should be appended, false to overwriteNullPointerException - if the file name or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(String fileName, String charsetName) throws IOException
builder()fileName - the name of the file to write to, not nullcharsetName - the name of the requested charset, not nullNullPointerException - if the file name or encoding is nullIOException - in case of an I/O error@Deprecated public FileWriterWithEncoding(String fileName, String charsetName, boolean append) throws IOException
builder()fileName - the name of the file to write to, not nullcharsetName - the name of the requested charset, not nullappend - true if content should be appended, false to overwriteNullPointerException - if the file name or encoding is nullIOException - in case of an I/O errorpublic static FileWriterWithEncoding.Builder builder()
FileWriterWithEncoding.Builder.FileWriterWithEncoding.Builder.Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.