Java FileInputStream Read writeFile(InputStream fileInputStream, OutputStream outputStream)

Here you can find the source of writeFile(InputStream fileInputStream, OutputStream outputStream)

Description

write File

License

Apache License

Declaration

public static void writeFile(InputStream fileInputStream, OutputStream outputStream) throws IOException 

Method Source Code


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

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

public class Main {
    public static void writeFile(InputStream fileInputStream, OutputStream outputStream) throws IOException {
        try {/*www .j a  v  a 2s.  c  o  m*/
            byte[] buffer = new byte[1024];
            int bytesRead;

            while ((bytesRead = fileInputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            fileInputStream.close();
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            outputStream.close();
        }
    }
}

Related

  1. readFileToBytes(String path)
  2. readFileToStr(String fn, String charset)
  3. readFileUTF8(String file)
  4. readFileUTF_8(String filePath)
  5. writeFile(File file, byte[] buffer, ZipOutputStream zos)
  6. writeFile(OutputStream os, File f)
  7. writeFile(String path, OutputStream out)
  8. writeFileToOutputStream(File file, OutputStream output)
  9. writeFileToStream(File file, OutputStream os)