Java Utililty Methods Write String to File

List of utility methods to do Write String to File

Description

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

Method

voidwriteFile(String fileName, String output)
Write a String to a file
File file = openFile(fileName);
if (file == null) {
    throw new FileNotFoundException(fileName);
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"));
try {
    out.write(output);
    out.flush();
...
voidwriteFile(String filename, String s)
write File
File f = new File(filename);
writeFile(f, s);
voidwriteFile(String fileName, String source)
write File
FileWriter fos = new FileWriter(fileName);
for (int i = 0; i < source.length(); i++) {
    fos.write(source.charAt(i));
fos.close();
return;
voidwriteFile(String filename, String str)
Writes
str
to
filename
, overwriting it if it's already there.
FileWriter out = new FileWriter(filename);
out.write(str, 0, str.length());
out.close();
voidwriteFile(String filename, String string)
Writes the specified string to the file with the specified name.
writeFile(new File(filename), string);
FilewriteFile(String filename, String text)
write File
FileOutputStream out = new FileOutputStream(filename);
out.write(text.getBytes("UTF-8"));
out.close();
return new File(filename);
voidwriteFile(String filename, String text)
Write a text file.
File file = new File(filename);
if (null != file.getParentFile()) {
    file.getParentFile().mkdirs();
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
String[] lines = text.split("#");
for (String line : lines) {
    writer.write(line);
...
voidwriteFile(String filename, String text)
write File
try {
    FileWriter fstream = new FileWriter(filename);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(text);
    out.close();
} catch (Exception e) {
    System.err.println("Error: " + e.getMessage());
voidwriteFile(String fileName, String text)
write File
FileWriter fw = new FileWriter(fileName, true);
try {
    fw.write(text, 0, text.length());
} catch (IOException ioe) {
    throw new IOException("Write text to " + fileName + " fail!");
} finally {
    fw.close();
voidwriteFile(String filename, String text, boolean create)
Write a text file
FileWriter fw = null;
PrintWriter pw = null;
if (create) {
    createDirectoriesForFile(filename);
try {
    fw = new FileWriter(filename);
    pw = new PrintWriter(fw);
...