Java Utililty Methods FileWriter Write

List of utility methods to do FileWriter Write

Description

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

Method

voidsave2DArray(float[][] data, String filePath)
save D Array
try {
    FileWriter writer = new FileWriter(filePath);
    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[0].length; j++) {
            writer.write(String.format("%5.4f ", data[i][j]));
        writer.write("\n");
    writer.close();
} catch (IOException e) {
    e.printStackTrace();
intsave2File(String fileName, String content)
save File
File file = new File(fileName);
try {
    if (file.exists() == false) {
        file.createNewFile();
    FileWriter writer = new FileWriter(fileName);
    writer.write(content);
    writer.close();
...
voidsave_array(double[] array, String fname)
savarray
FileWriter f = new FileWriter(fname);
BufferedWriter W = new BufferedWriter(f);
for (int i = 0; i < array.length; i++)
    W.write(array[i] + "\n");
W.flush();
W.close();
f.close();
booleansaveAllToFile(String filename, String... strings)
save All To File
return saveAllToFile(new File(filename), strings);
voidsaveArrayNames(int[] array, String[] names, String fname)
save Array Names
FileWriter f = new FileWriter(fname);
BufferedWriter W = new BufferedWriter(f);
for (int i = 0; i < array.length; i++)
    W.write(names[i] + "\t" + array[i] + "\n");
W.flush();
W.close();
f.close();
voidsaveAuthFile(String fileName, String raw)
save Auth File
FileWriter f = null;
try {
    f = new FileWriter(fileName, false);
    f.write(raw);
    f.flush();
    f.close();
} catch (Exception e) {
    throw new RuntimeException(e);
...
voidsaveBufferInFile(String buffer, File filename)
save Buffer In File
BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter(filename));
    writer.write(buffer);
} finally {
    if (writer != null) {
        writer.close();
voidsaveCCS(Map contributionScore, String diseaseState, String file)
save CCS
File f = new File(file);
if (!f.exists()) {
    f.createNewFile();
FileWriter fw = new FileWriter(f.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("expression" + "\t" + diseaseState);
bw.newLine();
...
voidsaveColumn(int[] density, String filename)
save Column
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filename)));
for (int n : density) {
    bw.write(Integer.valueOf(n).toString() + "\n");
bw.close();
voidsaveConfig(File conf, Map data)
save Config
try (BufferedWriter bw = new BufferedWriter(new FileWriter(conf))) {
    bw.write("#Written " + new Date().toLocaleString() + "\n");
    for (Entry<String, String> e : data.entrySet()) {
        bw.write(e.getKey() + "=" + e.getValue() + "\n");
} catch (IOException ex) {
    ex.printStackTrace();