URL讀取網路資源
阿新 • • 發佈:2018-12-30
package Url;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class URLTest {
/**
* @param URL測試
* @throws IOException
*/
public static void main(String[] args) throws IOException {
URL url = new URL("https://www.cnblogs.com/zhp2016/p/6005460.html");
InputStreamReader in = new InputStreamReader(url.openStream());
BufferedReader buffer = new BufferedReader(in);
String str;
while ((str = buffer.readLine()) != null) {
System.out.println(str);
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class URLTest {
/**
* @param URL測試
* @throws IOException
*/
public static void main(String[] args) throws IOException {
URL url = new URL("https://www.cnblogs.com/zhp2016/p/6005460.html");
InputStreamReader in = new InputStreamReader(url.openStream());
BufferedReader buffer = new BufferedReader(in);
String str;
while ((str = buffer.readLine()) != null) {
System.out.println(str);
}
}
}