package com.zkx.demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
/**
* java代码读取网络服务器资源
*
*/
public class Demo1 {
public static void main(String[] args) throws Exception {
// 1.准备url对象
URL url = new URL("https://xxx");
// 2.打开服务器连接,得到连接对象
URLConnection conn = url.openConnection();
// 3.获取加载数据的字节输入流
InputStream is = conn.getInputStream();
// 4.将is装饰为能一次读取一行的字符输入流
BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
// 5.加载一行
String line = br.readLine();
// 6显示
System.out.println(line);
// 7.释放资源
br.close();
}
}