Java如何创建URL对象?
package org.nhooo.example.network;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class URLDemo {
public static void main(String[] args) {
try {
//通过分别指定每个参数来创建url对象,包括
//协议,主机名,端口号和页面名称
URL url = new URL("https", "nhooo.com", 443, "/index.php");
//我们也可以在一行中指定地址
url = new URL("https://nhooo.com:443/index.php");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短