Java File Write fileWriteOut(InputStream in, String outPath)

Here you can find the source of fileWriteOut(InputStream in, String outPath)

Description

file Write Out

License

Apache License

Declaration

public static long fileWriteOut(InputStream in, String outPath) throws IOException 

Method Source Code


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

import java.io.BufferedOutputStream;

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

import java.io.OutputStream;

public class Main {

    public static long fileWriteOut(InputStream in, String outPath) throws IOException {
        byte[] buf = new byte[1024];
        int length = 0;
        long fileSize = 0;
        OutputStream out = null;//from   w w w .  ja v a 2 s. c o  m
        try {
            out = new BufferedOutputStream(new FileOutputStream(outPath));
            while ((length = in.read(buf)) > 0) {
                fileSize += length;
                out.write(buf, 0, length);
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            in.close();
            out.close();
            in = null;
            out = null;
        }

        return fileSize;
    }
}

Related

  1. fileWrite(String fileName, String str)
  2. fileWrite(String filePath, String data)
  3. fileWrite(String filePath, String fileName, String content)
  4. fileWrite(String path, int format, String content, Object bytesObj)
  5. fileWrite(String[] text, File file)
  6. fileWriter(int startpt, int letter)
  7. fileWriter(String outfile, String contents, boolean append)
  8. fileWriteString(String filePath, String strWrite, boolean append)