标签:cat stack null buffer jar tps zha www end
package com.zbb.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import org.jsoup.Jsoup;
public class Test02 {
public static void main(String[] a) {
String str="https://www.baidu.com";
t1(str);
}
/**
* 需要用到 jsoup-1.7.2.jar
*
* <dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
* @Title: t2
* @author zhaozhen
* @param str
*/
public static void t2(String str) {
String html="";
try {
html = Jsoup.connect(str).get().html();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(html);
}
public static void t1(String str) {
try {
URL url = new URL(str);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("index.html"));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
writer.write(line);
writer.newLine();
}
reader.close();
writer.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
标签:cat stack null buffer jar tps zha www end
原文地址:https://www.cnblogs.com/super-admin/p/9540758.html