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

voidwriteStringToFile(File file, String text, boolean append)
Writes text to the file.
FileWriter writer = new FileWriter(file, append);
try {
    writer.write(text);
} finally {
    writer.close();
voidwriteStringToFile(File file, String xml)
write String To File
BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter(file));
    writer.write(xml);
} catch (FileNotFoundException ex) {
    ex.printStackTrace();
} catch (IOException ex) {
    writer.close();
...
voidwriteStringToFile(File outf, String str)
Write a String to a file.
if (outf == null || str == null) {
    return;
File dirf = outf.getParentFile();
if (dirf != null && !dirf.exists()) {
    dirf.mkdirs();
FileOutputStream fout = new FileOutputStream(outf);
...
voidwriteStringToFile(File outFile, String s)
write String To File
OutputStreamWriter writer = null;
try {
    outFile.getParentFile().mkdirs();
    final OutputStream out = new FileOutputStream(outFile);
    writer = new OutputStreamWriter(out, "UTF-8");
    writer.write(s, 0, s.length());
} finally {
    try {
...
booleanwriteStringToFile(File p_out, String p_str)
Writes a string to a file
try {
    OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(p_out));
    osw.write(p_str + System.lineSeparator());
    osw.flush();
    osw.close();
} catch (FileNotFoundException e) {
    return false;
} catch (IOException e) {
...
voidwriteStringToFile(File pFile, String pString)
Writes the content of a string to a file.
try (PrintWriter out = new PrintWriter(pFile)) {
    out.print(pString);
voidwriteStringToFile(final File file, final String data)
write String To File
try {
    final OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file, false));
    outputStream.write(data.getBytes("UTF-8"));
    outputStream.close();
} catch (IOException e) {
    throw new RuntimeException("could not write file for debug cache", e);
voidwriteStringToFile(final File file, final String data)
write String To File
try {
    final OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file, false));
    outputStream.write(data.getBytes("UTF-8"));
    outputStream.close();
} catch (IOException e) {
    throw new RuntimeException("could not write file for debug cache", e);
voidwriteStringToFile(final String path, final String output)
This method appends a string to a textfile
try {
    FileWriter fw = new FileWriter(path, false);
    fw.append(output);
    fw.close();
} catch (IOException e) {
    e.printStackTrace();
voidwriteStringToFile(final String string, final File file)
Writes a string to a file.
createFile(file);
try (PrintWriter printWriter = new PrintWriter(file)) {
    printWriter.print(string);