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

booleanwriteStringToFile(String filename, String stringToWrite)
write String To File
try {
    FileWriter writer = new FileWriter(new File(filename));
    BufferedWriter bw = new BufferedWriter(writer);
    bw.write(stringToWrite);
    bw.flush();
    bw.close();
    return true;
} catch (IOException e) {
...
voidwriteStringToFile(String filename, String text)
write String To File
FileOutputStream stream = null;
PrintStream out = null;
try {
    stream = new FileOutputStream(filename);
    out = new PrintStream(stream);
    out.print(text);
} catch (Exception ex) {
    ex.printStackTrace();
...
voidWriteStringToFile(String fn, String dest)
Write string to file.
FileOutputStream fo = null;
try {
    fo = new FileOutputStream(fn);
    fo.write(dest.getBytes());
    fo.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
...
booleanwriteStringToFile(String fullPath, byte[] fileBytes)
write String To File
try {
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fullPath));
    bos.write(fileBytes);
    bos.flush();
    bos.close();
} catch (IOException ex) {
    ex.printStackTrace();
    return false;
...
booleanwriteStringToFile(String fullPath, String content)
write String To File
try {
    Writer output = null;
    File file = new File(fullPath);
    if (!file.exists()) {
        file.createNewFile();
    output = new BufferedWriter(new FileWriter(file));
    output.write(content);
...
voidwriteStringToFile(String jsonStr, File file)
write String To File
try {
    OutputStream out = new FileOutputStream(file);
    ByteArrayInputStream in = new ByteArrayInputStream(jsonStr.getBytes());
    byte[] buffer = new byte[1024];
    int len = 0;
    while ((len = in.read(buffer, 0, 1024)) != -1) {
        out.write(buffer, 0, len);
    in.close();
    out.close();
} catch (Exception e) {
voidwriteStringToFile(String macroContent, File file)
write String To File
try {
    java.io.FileWriter w = new java.io.FileWriter(file);
    w.write(macroContent);
    w.close();
} catch (Exception e) {
voidwriteStringToFile(String modifiedLine, String filePath)
write String To File
BufferedWriter bw = null;
try {
    bw = new BufferedWriter(new FileWriter(filePath, true));
    bw.write(modifiedLine + "\n");
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
...
voidwriteStringToFile(String path, String content)
write String To File
File f = new File(path);
FileOutputStream out = new FileOutputStream(f);
out.write(content.getBytes());
out.close();
voidwriteStringToFile(String path, String content)
write String To File
File file = new File(path);
BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter(file));
    writer.write(content);
} finally {
    if (writer != null)
        writer.close();
...