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 生日广州男生祝福语简短