copy InputStream to a File as Location - Android android.view.inputmethod

Android examples for android.view.inputmethod:KeyBoard

Description

copy InputStream to a File as Location

Demo Code

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 final boolean copy(InputStream is, File target) {
        OutputStream os = null;/*from ww w  .  ja v  a  2  s.c  o m*/

        try {
            os = new FileOutputStream(target);

            int read = 0;
            byte[] bytes = new byte[1024];
            while ((read = is.read(bytes)) != -1) {
                os.write(bytes, 0, read);
            }

            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ignore) {
                }
            }
            if (os != null) {
                try {
                    os.close();
                } catch (IOException ignore) {
                }
            }
        }
    }

}

Related Tutorials