_Ritchie

Java通过URL获取资源

public static void main() throws IOException { 
                URL url = new URL("https://www.baidu.com/img/bdlogo.png"); 
                Object obj = url.getContent(); 
                System.out.println(obj.getClass().getName()); 
        } 



public static void main(String[] args) throws IOException {
		String urls = "https://www.baidu.com";
		URL url = new URL(urls);
		URLConnection uc = url.openConnection();
		InputStream is = uc.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		String line = null;
		while ((line = br.readLine()) != null) {
			System.out.println(line);
		}
	}


posted on 2015-10-24 12:19  _Ritchie  阅读(236)  评论(0编辑  收藏  举报

导航