第一步。网络文件下载与从本地获取是不一样的,需要用URL类去打开连接从而获得输入流,其中path为完整路径包括http请求头的,inputStream注意在程序的finally中关闭,如下代码
/**
* 获取外部文件流
*/
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(3 * 1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; D