Java FileOutputStream Write saveFile(final InputStream in, final String path, final String fileName)

Here you can find the source of saveFile(final InputStream in, final String path, final String fileName)

Description

save File

License

Open Source License

Declaration

public static void saveFile(final InputStream in, final String path, final String fileName) throws IOException 

Method Source Code

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

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

public class Main {
    public static void saveFile(final InputStream in, final String path, final String fileName) throws IOException {
        OutputStream os = null;//  w ww  .  j  ava  2 s.  c  o m
        try {
            File distDir = new File(path);
            if (!distDir.exists()) {
                distDir.mkdirs();
            }
            os = new FileOutputStream(new File(distDir, fileName));
            byte[] buffer = new byte[256];
            int len = in.read(buffer);
            while (len != -1) {
                os.write(buffer, 0, len);
                len = in.read(buffer);
            }
        } catch (IOException e) {
            throw new IOException();
        } finally {
            if (null != os)
                os.close();
            if (null != in)
                in.close();
        }
    }
}

Related

  1. saveFile(File file, String fileName, String filesDirectory)
  2. saveFile(File file, String savePath)
  3. saveFile(final byte[] bytes, final File target)
  4. saveFile(final File file, final byte[] dataToSave)
  5. saveFile(final File file, final String contents, final String encoding)
  6. saveFile(final String filename, final String s1, final String textOut, final String s3)
  7. saveFile(InputStream is, File file)
  8. saveFile(InputStream is, String destDir, String fileName)
  9. savefile(InputStream source, String destination)