Here you can find the source of downloadFromUrl(String urlString, PrintStream logger)
public static String downloadFromUrl(String urlString, PrintStream logger) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.URL; import java.net.URLConnection; public class Main { public static String downloadFromUrl(String urlString, PrintStream logger) throws IOException { logger.println("downloadFromUrl: " + urlString); InputStream is = null;// w w w.ja v a2 s.c o m FileOutputStream fos = null; long timeStamp = System.currentTimeMillis(); URL url = new URL(urlString); File tempFile = File.createTempFile("instrumented-" + timeStamp, ".apk"); try { URLConnection urlConn = url.openConnection();//connect is = urlConn.getInputStream(); //get connection inputstream fos = new FileOutputStream(tempFile); //open outputstream to local file byte[] buffer = new byte[4096]; //declare 4KB buffer int len; //while we have availble data, continue downloading and storing to local file while ((len = is.read(buffer)) > 0) { fos.write(buffer, 0, len); } } finally { try { if (is != null) { is.close(); } } finally { if (fos != null) { fos.close(); } } } return tempFile.getPath(); } }