Java PrintWriter Write saveToFile(String buf, String fileName)

Here you can find the source of saveToFile(String buf, String fileName)

Description

save To File

License

Apache License

Declaration

public static void saveToFile(String buf, String fileName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.FileOutputStream;

import java.io.PrintWriter;

public class Main {
    public static void saveToFile(String buf, String fileName) {
        try (PrintWriter out = new PrintWriter(fileName)) {
            out.println(buf);/* w  w  w . j a  v  a  2s .co m*/
        } catch (Exception e) {
            throw new RuntimeException("Failed to write content to file " + fileName, e);
        }
    }

    public static void saveToFile(byte[] buf, String fileName) {
        try (FileOutputStream fos = new FileOutputStream(fileName)) {
            fos.write(buf);
        } catch (Exception e) {
            throw new RuntimeException("Failed to write content to file " + fileName, e);
        }
    }
}

Related

  1. saveStringBufferTofile(String fileName, StringBuffer sb)
  2. saveStrings(final String filename, final String[] sArray)
  3. saveStrings(String filename, String data[])
  4. saveStrings(String theFilePath, String[] theStrings)
  5. saveStringToFile(String text, String path)
  6. saveToFile(String path, String data)