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 结婚多层蛋糕祝福语简短