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(File file, String content, boolean append)
write String
try {
    if (!file.exists()) {
        file.getParentFile().mkdirs();
        file.createNewFile();
    final FileWriter fileWriter = new FileWriter(file, append);
    fileWriter.append(content);
    fileWriter.close();
...
voidwriteString(File file, String data)
write String
PrintWriter out = null;
try {
    out = new PrintWriter(new FileOutputStream(file));
    out.print(data);
} finally {
    if (out != null)
        out.close();
voidwriteString(File file, String s, int bufferSize, String encoding)
Writes string to a file.
if (s == null) {
    return;
FileOutputStream fos = null;
OutputStreamWriter osw = null;
BufferedWriter out = null;
try {
    fos = new FileOutputStream(file);
...
voidwriteString(File file, String str)
write String
OutputStream output = new FileOutputStream(file);
writeString(output, str);
voidwriteString(File file, String str, String encoding)
write String
try (Writer out = new OutputStreamWriter(new FileOutputStream(file), encoding)) {
    out.write(str);
voidwriteString(File file, String string)
write String
writeString(file, string, "UTF-8");
voidwriteString(File file, String string)
write String
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(file, false);
    fos.write(string.getBytes("UTF-8"));
} catch (Exception e) {
} finally {
    close(null, fos);
voidwriteString(File outputFile, String text)
write String
writeString(outputFile, text, DEFAULT_ENCODING);
voidwriteString(FileWriter fw, String s)
Write string
for (int i = 0; i < s.length(); i++) {
    fw.write((int) s.charAt(i));
voidwriteString(final ObjectOutput objectOut, final String str)
Writes (serializes) a string using the specified ObjectOutput interface.
objectOut.writeObject(str);