Java InputStream to OutputStream copyStream(InputStream fis, OutputStream fos)

Here you can find the source of copyStream(InputStream fis, OutputStream fos)

Description

copy Stream

License

Open Source License

Declaration

public static void copyStream(InputStream fis, OutputStream fos) 

Method Source Code

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

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

public class Main {
    public static void copyStream(InputStream fis, OutputStream fos) {
        try {//from w  w w. j a v a  2 s .  co m
            byte[] buffer = new byte[0xFFFF];
            for (int len; (len = fis.read(buffer)) != -1;)
                fos.write(buffer, 0, len);
        } catch (IOException e) {
            System.err.println(e);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. copyStream(final InputStream is, final OutputStream os)
  2. copyStream(final InputStream is, final OutputStream out, final Long amount, final int bufferSize)
  3. copyStream(final InputStream source, final OutputStream target)
  4. copyStream(final InputStream src, OutputStream dest)
  5. copyStream(final OutputStream to, final InputStream from)
  6. copyStream(InputStream from, OutputStream to)
  7. copyStream(InputStream in, boolean closeIn, OutputStream out, boolean closeOut)
  8. copyStream(InputStream in, File outputFile)
  9. copyStream(InputStream in, FileOutputStream out, IProgressMonitor monitor, int length)