Java Text File Save writeFile(String targetPath, String filename, byte[] content)

Here you can find the source of writeFile(String targetPath, String filename, byte[] content)

Description

write File

License

Open Source License

Declaration

public static boolean writeFile(String targetPath, String filename, byte[] content) 

Method Source Code


//package com.java2s;
import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

public class Main {
    public static boolean writeFile(String targetPath, String filename, byte[] content) {

        boolean ok = false;

        if (content != null && targetPath != null && targetPath.length() > 0 && filename != null
                && filename.length() > 0) {

            BufferedOutputStream bos = null;

            if (!targetPath.endsWith(File.separator)) {
                targetPath += File.separator;
            }//from   w w  w  . j a  va 2s. c o m

            try {
                FileOutputStream fos;
                fos = new FileOutputStream(new File(targetPath + filename));
                bos = new BufferedOutputStream(fos);
                bos.write(content);
                bos.flush();
                ok = true;
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (bos != null) {
                    try {
                        bos.close();
                    } catch (Exception e) {
                    }
                }
            }

        }

        return ok;

    }
}

Related

  1. writeFile(String str, File f)
  2. writeFile(String str, String filename, boolean append)
  3. writeFile(String string, File file)
  4. writeFile(String string, File location, boolean forceASCII)
  5. writeFile(String tailored, File f)
  6. writeFile(String text, File file, boolean append)
  7. writeFile(String text, File outf)
  8. writeFile(String text, File target)
  9. writeFile(String txt, File fyl)