copy File from InputStream to OutputStream by 1K buffer - Android File Input Output

Android examples for File Input Output:InputStream

Description

copy File from InputStream to OutputStream by 1K buffer

Demo Code


//package com.java2s;

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

public class Main {
    static private void copyFile(InputStream in, OutputStream out)
            throws IOException {
        byte[] buffer = new byte[1024];
        int read;

        // Copy from input stream to output stream
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);/* w  w  w .  j  a  v  a  2 s .c  om*/
        }
    }
}

Related Tutorials