package com.oracle.test;
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.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
public class Test {
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.baidu.com");
//下载网络资源
InputStream is = url.openStream();
Reader reader = new InputStreamReader(is,"utf-8");
//保存到本地
OutputStream out = new FileOutputStream("F:\\baidu.html");
OutputStreamWriter osw = new OutputStreamWriter(out, "utf-8");
char[] c = new char[1024];
int i = 0;
StringBuffer sb = new StringBuffer();
while((i=reader.read(c))!=-1){
sb.append(c, 0, i);//把下载的内容存到可变字符串中
}
String str = sb.toString();
str = str.replace("src=//", "src=http://");
osw.write(str);
osw.close();
out.close();
reader.close();
is.close();
}
}