Java FileWriter Write saveStats(String filename, String log)

Here you can find the source of saveStats(String filename, String log)

Description

save Stats

License

Open Source License

Declaration

public static void saveStats(String filename, String log) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void saveStats(String filename, String log) {
        BufferedWriter bw = null;
        FileWriter fw = null;//w  w w . j  a  v a 2  s  . com

        try {

            String data = log;

            File file = new File(filename);

            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            // true = append file
            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();

            }
        }

    }
}

Related

  1. saveMetadata(Map metadata, File file)
  2. saveModelInFile(final String model, final String filename)
  3. savePValue2File(double[] pValue, String fileName)
  4. saveSeqAln(String[] alnSequences, String filePath)
  5. saveSimpleTextFile(String data, String path, String filename)
  6. saveString(File filename, String content)
  7. saveString(String filePath, String content)
  8. saveString(String location, String content)
  9. saveStringFile(String fileName, String str)