url
package cn_1;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
public class Test {
/*
* http://ejz3told02kzmb4r8us7o74salizhhcqdbdexa7ple73ascwuz.902033.com:9305/task/looktask/YanZheng.htm?taskid=10656264
/*
* http://ejz3told02kzmb4r8us7o74salizhhcqdbdexa7ple73ascwuz.902033.com:9305/task/looktask/YanZheng.htm?taskid=10656264
*/
//url:{协议}://{用户名}:{密码}@{主机名}:{端口号}/{路径}/{文件}?{参数}
public static void main(String[] args) throws IOException {
URL u = new URL("http://www.mlzhx.cn/"); // 主页
/*
* System.out.println(u.getPort()); // 获取资源流 InputStream is =
* u.openStream(); byte[] flush = new byte[1024]; int len = 0; while
* ((len = is.read(flush)) != -1) { System.out.println(new String(flush,
* 0, len)); } is.close();
*/
/*
* // 以上出现乱码,所以用转换流 BufferedReader fr = new BufferedReader(new
* InputStreamReader(u.openStream(), "utf-8")); String s = null;
* while((s=fr.readLine())!=null){ System.out.println(s); } fr.close();
*/
// 将捕获的文件输出到一个制定的.html文件中
BufferedReader fr = new BufferedReader(new InputStreamReader(u.openStream(), "utf-8"));
BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("a.txt"), "utf-8"));
//url:{协议}://{用户名}:{密码}@{主机名}:{端口号}/{路径}/{文件}?{参数}
public static void main(String[] args) throws IOException {
URL u = new URL("http://www.mlzhx.cn/"); // 主页
/*
* System.out.println(u.getPort()); // 获取资源流 InputStream is =
* u.openStream(); byte[] flush = new byte[1024]; int len = 0; while
* ((len = is.read(flush)) != -1) { System.out.println(new String(flush,
* 0, len)); } is.close();
*/
/*
* // 以上出现乱码,所以用转换流 BufferedReader fr = new BufferedReader(new
* InputStreamReader(u.openStream(), "utf-8")); String s = null;
* while((s=fr.readLine())!=null){ System.out.println(s); } fr.close();
*/
// 将捕获的文件输出到一个制定的.html文件中
BufferedReader fr = new BufferedReader(new InputStreamReader(u.openStream(), "utf-8"));
BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("a.txt"), "utf-8"));
String ss = null;
while((ss=fr.readLine())!=null){
bf.append(ss);
bf.newLine();
}
bf.flush();
fr.close();
bf.close();
}
}
while((ss=fr.readLine())!=null){
bf.append(ss);
bf.newLine();
}
bf.flush();
fr.close();
bf.close();
}
}