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 祝福语驱散霉运的话简短