private void copyResource(InputStream resource, File file) {

        try {
            OutputStream out = new FileOutputStream(file);

            int lenght;
            byte[] buf = new byte[1024];

            while ((lenght = resource.read(buf)) > 0) {
                out.write(buf, 0, lenght);
            }

            out.close();
            resource.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }