Java FileOutputStream Write saveFile(String content, String path)

Here you can find the source of saveFile(String content, String path)

Description

save File

License

Open Source License

Declaration

public static File saveFile(String content, String path) 

Method Source Code


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

import java.io.BufferedOutputStream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static File saveFile(String content, String path) {

        BufferedOutputStream stream = null;
        File file = null;//from   w  w  w. j av  a2 s. co m
        try {
            file = new File(path);
            if (!file.exists())
                file.createNewFile();

            FileOutputStream fstream = new FileOutputStream(file);
            stream = new BufferedOutputStream(fstream);
            byte[] b = content.getBytes("UTF-8");
            stream.write(b);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return file;
    }
}

Related

  1. saveFile(final String filename, final String s1, final String textOut, final String s3)
  2. saveFile(InputStream is, File file)
  3. saveFile(InputStream is, String destDir, String fileName)
  4. savefile(InputStream source, String destination)
  5. saveFile(InputStream uploadedInputStream, String serverLocation)
  6. saveFile(String desEncryptTempFile, byte[] text)
  7. saveFile(String destinationFile, String contents)
  8. saveFile(String dir, String fileName, String data)
  9. saveFile(String file, String text)