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);
		}
	}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章