Java Utililty Methods Text File Write

List of utility methods to do Text File Write

Description

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

Method

voidwriteString(StringBuilder out, CharSequence value, boolean escapeXML)
Encodes a String in JavaScript Object Notation.
if (value == null) {
    out.append("null");
} else {
    out.append('\'');
    for (int i = 0; i < value.length(); i++) {
        char ch = value.charAt(i);
        _escapeChar(out, ch, escapeXML);
    out.append('\'');
voidwriteStringField(String name, String value, JsonGenerator jgen)
write String Field
if (value != null) {
    jgen.writeStringField(name, value);
voidwriteStringFile(String FileName, String text)
Write text to a file called Filename
try {
    FileOutputStream fs = new FileOutputStream(FileName);
    PrintStream out = new PrintStream(fs);
    out.println(text);
    out.close();
} catch (IOException ex) {
    throw new IllegalArgumentException(ex.toString()); 
voidwriteStringInto(String s, File outputFile)
Writes a string into a file.
InputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
copyStream(in, outputFile);
voidwriteStringInto(String s, File outputFile)
Writes a string into a file.
InputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
copyStream(in, outputFile);
voidwriteStringListToFile(File file, ArrayList lines)
Writes a string list to a file.
if (file == null) {
    throw new IllegalArgumentException("File should not be null.");
if (!file.exists()) {
    throw new FileNotFoundException("File does not exist: " + file);
if (!file.isFile()) {
    throw new IllegalArgumentException("Should not be a directory: " + file);
...
voidwriteStringListToFile(File file, List lines)
Writes a string list to a file.
if (file == null) {
    throw new IllegalArgumentException("File should not be null.");
try (BufferedWriter output = new BufferedWriter(new FileWriter(file))) {
    for (String line : lines) {
        output.write(line + "\n");
voidwriteStringTo(File outFile, String data)
write String To
FileOutputStream outputStream = null;
try {
    outputStream = new FileOutputStream(outFile);
    outputStream.write(data.getBytes());
    outputStream.flush();
} finally {
    if (outputStream != null) {
        outputStream.close();
...
voidwriteStringTo(String _value, File _target)
write String To
BufferedWriter writer = new BufferedWriter(new FileWriter(_target));
try {
    if (null != _value)
        writer.write(_value);
} finally {
    writer.close();
voidwriteStringToFile(@Nonnull String string, @Nonnull final File file)
Writes a String to a File .
checkNotNull(string, "string cannot be null.");
checkNotNull(file, "file cannot be null.");
try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
    string = string.replaceAll("\n", System.getProperty("line.separator"));
    out.write(string);