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 content, String writePath, String charCoder)
write File
try {
    File file = new File(writePath);
    OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file), charCoder);
    BufferedWriter reader = new BufferedWriter(osw);
    reader.write(content);
    osw.flush();
    reader.close();
    osw.close();
...
voidwriteFile(String contents, File f)
Writes a string to a file.
FileWriter fw = null;
try {
    fw = new FileWriter(f);
    fw.write(contents);
} catch (IOException e) {
    throw new RuntimeException(
            "workdir is " + System.getProperty("user.dir") + ", couldn't write contents to file: " + e);
} finally {
...
voidwriteFile(String contents, File file)
Write contents to a file
BufferedWriter out = null;
try {
    out = new BufferedWriter(new FileWriter(file));
    out.write(contents);
} finally {
    if (out != null)
        out.close();
voidwriteFile(String contents, String filename)
Writes the given string into the given file.
FileWriter fw = new FileWriter(filename);
fw.write(contents);
fw.flush();
fw.close();
voidwriteFile(String contents, String fileName)
write File
writeFile(contents, new File(".", fileName));
voidwriteFile(String data, File file)
write File
writeFile(data, file, false);
voidwriteFile(String data, File tar)
write File
writeFile(data.getBytes(), tar);
voidwriteFile(String datafile, String filePath)
write File
try {
    Writer output = null;
    File file = new File(filePath);
    output = new FileWriter(file);
    output.write(datafile);
    output.close();
} catch (IOException ex) {
    ex.printStackTrace();
...
voidwriteFile(String destination, byte[] data, boolean append)
writeFile
File temp = new File(destination);
if (temp.exists() && append == true) {
    FileOutputStream fos = new FileOutputStream(temp, true);
    try {
        fos.write(data);
        fos.flush();
    } finally {
        fos.close();
...
voidwriteFile(String filename, Object object)
write File
try {
    FileOutputStream fout = new FileOutputStream(filename);
    ObjectOutputStream oos = new ObjectOutputStream(fout);
    oos.writeObject(object);
    oos.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
...