Java FileOutputStream Write saveFile(String pathname, String fileName, String contents)

Here you can find the source of saveFile(String pathname, String fileName, String contents)

Description

save File

License

Apache License

Declaration

public final static void saveFile(String pathname, String fileName, String contents) throws IOException 

Method Source Code


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

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

public class Main {
    public final static void saveFile(String pathname, String fileName, String contents) throws IOException {

        File filePath = new File(pathname);

        if (!filePath.exists())
            filePath.mkdirs();/*www.j  a va2 s . c o m*/

        File file = new File(filePath, fileName);
        if (file.exists())
            file.createNewFile();

        OutputStream os = null;

        try {
            os = new BufferedOutputStream(new FileOutputStream(file));
            os.write(contents.getBytes());
            os.flush();
        } catch (IOException e) {
            throw e;
        } finally {
            if (os != null) {
                os.close();
                os = null;
            }
        }

    }
}

Related

  1. saveFile(String filename, String content)
  2. saveFile(String fileName, String contents)
  3. saveFile(String name, byte[] data)
  4. saveFile(String path, byte[] content)
  5. saveFile(String pathFile, String data)
  6. saveFile(String pathRoot, String subPath, boolean isFoler, InputStream in)
  7. saveFile(String text, File saveFile)
  8. saveFileBinary(final File file, final byte[] data)
  9. SaveFileFromInputStream(InputStream in, String fileName, String path)