从HTTP下载返回InputStream
//package com.nowjava;// 来自 时 代 J a v a - nowjava.com import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { /** * Download from HTTP, mustn't run in main thread, Caller need to apply permission themselves. * @param url * @return : null if there is some errors. */ public static InputStream download(String url) { try { URL mUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) mUrl .openConnection(); conn.setConnectTimeout(10000); /** from N o w J a v a . c o m - 时代Java**/ conn.setReadTimeout(10000); InputStream is = conn.getInputStream(); return is; // conn.setInstanceFollowRedirects(false); }