Java Utililty Methods Text File Save

List of utility methods to do Text File Save

Description

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

Method

voidwriteFile(String str, File f)
write File
if (!f.exists()) {
    if (!f.getParentFile().exists() && !f.getParentFile().mkdirs())
        throw new IOException("Unable to create dirs for file");
    if (!f.createNewFile())
        throw new IOException("Unable to create file");
FileWriter w = new FileWriter(f);
w.write(str);
...
voidwriteFile(String str, String filename, boolean append)
write File
int length = str.length();
FileWriter out = new FileWriter(filename, append);
out.write(str, 0, length);
out.close();
voidwriteFile(String string, File file)
Writes the string specified to the file specified.
try {
    ByteArrayInputStream bais = new ByteArrayInputStream(string.getBytes("UTF-8"));
    FileOutputStream fos = new FileOutputStream(file);
    copy(bais, fos);
    bais.close();
    fos.flush();
    fos.close();
} catch (Exception e) {
...
booleanwriteFile(String string, File location, boolean forceASCII)
write File
if (!location.exists())
    location.getParentFile().mkdirs();
try {
    if (location.exists())
        location.delete();
    location.createNewFile();
    if (!forceASCII) {
        FileWriter fstream = new FileWriter(location);
...
voidwriteFile(String tailored, File f)
write File
FileWriter fw = new FileWriter(f, false);
fw.write(tailored);
fw.close();
booleanwriteFile(String targetPath, String filename, byte[] content)
write File
boolean ok = false;
if (content != null && targetPath != null && targetPath.length() > 0 && filename != null
        && filename.length() > 0) {
    BufferedOutputStream bos = null;
    if (!targetPath.endsWith(File.separator)) {
        targetPath += File.separator;
    try {
...
voidwriteFile(String text, File file, boolean append)
write File
FileWriter fileWriter = new FileWriter(file, append);
fileWriter.write(text);
fileWriter.flush();
fileWriter.close();
voidwriteFile(String text, File outf)
write File
File parent = outf.getParentFile();
if (parent != null)
    parent.mkdirs();
FileWriter f = new FileWriter(outf);
PrintWriter pw = new PrintWriter(f);
pw.println(text);
pw.close();
f.close();
...
FilewriteFile(String text, File target)
Writes a text file.
try {
    FileWriter fout = new FileWriter(target);
    fout.write(text);
    fout.close();
    return target;
} catch (Exception ex) {
return null;
...
voidwriteFile(String txt, File fyl)
Write a file.
writeFile(txt.getBytes(), fyl);