public static boolean saveToFile(@Nullable final InputStream inputStream, @NonNull final File targetFile) {
        if (inputStream == null) {
            return false;
        }

        File tempFile = null;
        try {
            tempFile = File.createTempFile("download", null, targetFile.getParentFile());
            final FileOutputStream fos = new FileOutputStream(tempFile);
            IOUtils.copy(inputStream, fos);
            fos.close();
            return tempFile.renameTo(targetFile);
        } catch (final IOException e) {
            Log.e("FileUtils.saveToFile", e);
            deleteIgnoringFailure(tempFile);
            deleteIgnoringFailure(targetFile);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
        return false;
    }
Save a stream to a file.
<p/>
If the response could not be saved to the file due, for example, to a network error, the file will not exist when
this method returns.

@param inputStream the stream whose content will be saved
@param targetFile  the target file, which will be created if necessary
@return true if the operation was successful, false otherwise
main/src/main/java/cgeo/geocaching/utils/FileUtils.java