Util.java Source code

Java tutorial

Introduction

Here is the source code for Util.java

Source

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

public class Util {

    public static File copyFromStreamToFile(InputStream is, File file) {
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(file);
            byte[] buf = new byte[1024];
            int len;
            while ((len = is.read(buf)) > 0) {
                out.write(buf, 0, len);
            }

        } catch (Exception ex) {

        } finally {
            try {
                is.close();
                out.close();
            } catch (IOException ex) {

            }
        }
        return file;
    }

}