通过网络路径,返回输入流工具类

    public static byte[] getUrlData(String urlPath) throws Exception{
        URL url;
        byte[] data = null;
        InputStream input=null;
        try {
            url = new URL(urlPath);
            HttpURLConnection conn=(HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5*1000);
            conn.setRequestMethod("GET");
            int a=conn.getResponseCode();
            if( 200==conn.getResponseCode()){  //判断是否连接成功  发送数据
                input=conn.getInputStream();    //获得输入流
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return input;
    }

 

posted @ 2013-11-25 23:20  小小小小小小菜鸟  阅读(149)  评论(0编辑  收藏  举报