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

voidsaveMetadata(Map metadata, File file)
save Metadata
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
Gson gson = new Gson();
writer.write(gson.toJson(metadata));
writer.close();
FilesaveModelInFile(final String model, final String filename)
Creates and returns a file that contains the argument model as content.
final File f = new File(filename);
final BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write(model);
bw.close();
return f;
voidsavePValue2File(double[] pValue, String fileName)
save P Value File
FileWriter fw = null;
fw = new FileWriter(fileName);
String str = "";
if (pValue != null) {
    for (int i = 0; i < pValue.length; i++) {
        str = str + pValue[i];
        str = str + "\n";
} else {
    str = "null";
fw.write(str);
fw.close();
voidsaveSeqAln(String[] alnSequences, String filePath)
Save a multiple sequence alignment result as a fasta file.
FileWriter writer = new FileWriter(filePath);
for (int su = 0; su < alnSequences.length; su++) {
    writer.append(">Subunit_" + (su + 1) + "\n");
    writer.append(alnSequences[su] + "\n");
writer.flush();
writer.close();
voidsaveSimpleTextFile(String data, String path, String filename)
save Simple Text File
File file;
if ("".equals(path) || path == null) {
    file = new File(filename);
} else {
    makeDirs(path);
    file = new File(path + File.separator + filename);
saveSimpleTextFile(data, file);
...
voidsaveStats(String filename, String log)
save Stats
BufferedWriter bw = null;
FileWriter fw = null;
try {
    String data = log;
    File file = new File(filename);
    if (!file.exists()) {
        file.createNewFile();
    fw = new FileWriter(file.getAbsoluteFile(), true);
    bw = new BufferedWriter(fw);
    bw.write(data);
    System.out.println("Log Written : " + filename);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (bw != null)
            bw.close();
        if (fw != null)
            fw.close();
    } catch (IOException ex) {
        ex.printStackTrace();
voidsaveString(File filename, String content)
save String
FileWriter out = null;
try {
    out = new FileWriter(filename);
    out.write(content);
} catch (IOException e) {
    throw new RuntimeException(e);
} finally {
    if (out != null) {
...
voidsaveString(String filePath, String content)
save String
PrintWriter pw = null;
boolean autoFlush = true;
try {
    pw = new PrintWriter(new BufferedWriter(new FileWriter(filePath)), autoFlush);
} catch (IOException e) {
    e.printStackTrace();
    exit(1);
pw.print(content);
pw.close();
voidsaveString(String location, String content)
Saves a string to a file
File f = new File(location);
try {
    BufferedWriter writer = new BufferedWriter(new FileWriter(f));
    writer.write(content.toCharArray());
    writer.close();
    System.out.println("Wrote output "
            + "to: " + f.getAbsolutePath() + "\n");
} catch (IOException e) {
...
booleansaveStringFile(String fileName, String str)
Save a file
File f = new File(fileName);
try {
    PrintWriter w = new PrintWriter(new FileWriter(f));
    w.print(str);
    w.close();
} catch (java.io.IOException e) {
    System.err.println(e);
    return false;
...