Java Utililty Methods BufferedWriter Write

List of utility methods to do BufferedWriter Write

Description

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

Method

voidwriteFile(BufferedWriter fw, String line)
write File
fw.append(line + "\r\n");
booleanwriteFile(double[][] toWrite, String outName)
Write a double[][] with an arbitrary number of columns to a file.
BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter(new File(outName)));
    for (int l = 0; l < toWrite[0].length; l++) {
        String line = "";
        for (int c = 0; c < toWrite.length; c++) {
            if (c == toWrite.length - 1) {
                line += toWrite[c][l];
...
voidwriteFile(File dir, File fileRef, File newFileName, ClassLoader classLoader)
Writes fileRef to dir as newFileRef.
if (dir == null || fileRef == null || newFileName == null || "".equals(newFileName)
        || classLoader == null) {
    throw new NullPointerException("");
BufferedReader in = new BufferedReader(
        new InputStreamReader(classLoader.getResourceAsStream(fileRef.getPath())));
dir.mkdirs();
if (newFileName.getPath().lastIndexOf("/") > 0) {
...
voidwriteFile(File src, File dst)
write File
File parent = dst.getParentFile();
if (!parent.exists())
    parent.mkdirs();
byte[] bytes = loadBytes(new FileInputStream(src));
writeBytes(dst, bytes);
if (!dst.exists())
    throw new RuntimeException("UNABLE TO WRITE FILE: " + dst.getAbsolutePath());
voidwriteFile(Object msg)
write File
try {
    writer.write(msg + "\n");
} catch (IOException e) {
    e.printStackTrace();
voidwriteFile(String dir, String file, String content)
Write 'content' in 'dir'/'file'
File newDir = new File(dir);
newDir.mkdirs();
try (FileWriter fw = new FileWriter(dir + "/" + file, false);
        BufferedWriter output = new BufferedWriter(fw);) {
    output.write(content);
    output.flush();
    output.close();
} catch (Exception e) {
...
voidwriteFile(String directory, String content, String fileName, boolean deleteFileBeforeWriting)
write File
try {
    if (deleteFileBeforeWriting)
        deleteFile(directory + fileName);
    BufferedWriter out = new BufferedWriter(new FileWriter(directory + fileName, deleteFileBeforeWriting));
    out.write(content);
    out.close();
} catch (Exception e) {
    System.out.println("failed to write query");
...
voidWriteFile(String file)
Write File
try {
    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write("Halo Indonesia");
    out.write("\nBaris baru");
    out.newLine();
    out.write("Apa kabar?");
    out.close();
    System.out.println("ok");
...
voidwriteFile(String file, List data)
write File
BufferedWriter out = new BufferedWriter(new FileWriter(file));
for (String line : data) {
    out.write(line);
    out.newLine();
out.close();
voidwriteFile(String filename, ArrayList entries)
write File
File file = new File(filename);
file.delete();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
for (int i = 0; i < entries.size(); i++) {
    String entry = (String) entries.get(i);
    out.println(entry);
out.close();
...