Example usage for java.io BufferedWriter close

List of usage examples for java.io BufferedWriter close

Introduction

In this page you can find the example usage for java.io BufferedWriter close.

Prototype

@SuppressWarnings("try")
    public void close() throws IOException 

Source Link

Usage

From source file:Main.java

/**
 * Print out the spike trains so it can be analyzed by plotting software
 * @param file//  w ww .  j  a v a  2  s.  co  m
 * @param array
 */
public static void print(File file, double[] array) {
    FileWriter fstream = null;
    BufferedWriter out = null;

    try {
        fstream = new FileWriter(file);
        out = new BufferedWriter(fstream);
        for (int i = 0; i < array.length; i++) {
            out.write(array[i] + "\t");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {

        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (fstream != null) {
            try {
                fstream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}

From source file:oneDrive.OneDriveAPI.java

public static void createNewTokenFile(String accessToken) {
    BufferedWriter output = null;
    try {//from w  w w.j a  va 2s.c  o m
        File file = new File("SPsCredentials/OneDriveLogin.txt");
        output = new BufferedWriter(new FileWriter(file));
        output.write(accessToken);
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.j4velin.mapsmeasure.Util.java

/**
 * Writes the given trace of points to the given file in CSV format,
 * separated by ";"/*  w  w w.j  a  va 2  s  .co  m*/
 * 
 * @param f
 *            the file to write to
 * @param trace
 *            the trace to write
 * @throws IOException
 */
static void saveToFile(final File f, final Stack<LatLng> trace) throws IOException {
    if (!f.exists())
        f.createNewFile();
    BufferedWriter out = new BufferedWriter(new FileWriter(f));
    LatLng current;
    for (int i = 0; i < trace.size(); i++) {
        current = trace.get(i);
        out.append(current.latitude + ";" + current.longitude + "\n");
    }
    out.close();
}

From source file:com.folio3.parse.MainActivity.java

public static void writeLogToFile(Context context, String alert) {
    String eol = System.getProperty("line.separator");
    BufferedWriter writer = null;
    try {/* w w  w .  jav  a  2 s  .  co m*/
        FileOutputStream openFileOutput = context.openFileOutput(FILE, Context.MODE_APPEND);
        openFileOutput.write((alert + "\r\n").getBytes());
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}

From source file:com.thinkit.operationsys.util.FileUtil.java

/**
 * ?//from  w w w  . ja  va2s . c o  m
 *
 * @param fileName
 * @param data
 */
public static void write(String fileName, String data) {
    BufferedWriter bw = null;
    try {
        //         String name = getName(link) + "analyze.txt";
        bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName)));
        bw.write(data);
        bw.flush();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (null != bw) {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.kdmanalytics.toif.adaptor.SplintAdaptor.java

public static void writeToFile(String sb) throws IOException {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File tempFile = new File(tempDir, "toifLog");
    FileWriter fileWriter = new FileWriter(tempFile, true);
    BufferedWriter bw = new BufferedWriter(fileWriter);
    bw.write(sb);//from  w w  w. ja  va  2s  . c  o m
    bw.close();
}

From source file:com.germinus.easyconf.FileUtil.java

public static void write(File file, String s) throws IOException {
    if (file.getParent() != null) {
        mkdirs(file.getParent());/*www. j  ava  2 s  .c  o m*/
    }

    BufferedWriter bw = new BufferedWriter(new FileWriter(file));

    bw.flush();
    bw.write(s);
    bw.flush();

    bw.close();
}

From source file:com.valco.utility.FacturasUtility.java

public static void guardaXml(String name, String content, String path, Integer facturaId) throws Exception {
    try {//  w  ww  . j  a va2 s . c o  m
        File file = new File(path + name);
        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();
    } catch (Exception ex) {
        throw new Exception("Factura " + facturaId + ": Ocurrio un error al generar el PDF.");
    }

}

From source file:Main.java

public static void writeFile(String content, String path) {
    FileOutputStream fos = null;// w  ww . j  a v a2s. c om
    BufferedWriter bw = null;
    try {
        File file = new File(path);
        fos = new FileOutputStream(file);
        bw = new BufferedWriter(new OutputStreamWriter(fos, "GB2312"));
        bw.write(content);
    } catch (FileNotFoundException fnfe) {
        fnfe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        try {
            if (bw != null)
                bw.close();
            if (fos != null)
                fos.close();
        } catch (IOException ie) {
        }
    }
}

From source file:Main.java

public static boolean string2File(String res, File file) {
    if (file == null || res == null)
        return false;
    BufferedWriter bufferedWriter = null;
    try {/*from w ww .j a v  a  2s .c om*/
        bufferedWriter = new BufferedWriter(new FileWriter(file));
        bufferedWriter.write(res);
        bufferedWriter.flush();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        if (file.exists())
            file.delete();
        return false;
    } finally {
        try {
            if (bufferedWriter != null)
                bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}