package com.hcwy;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class Operate {
public static void convert2Html(String sSourceUrl,String sDestDir,String sHtmlFile) throws IOException
{
int HttpResult;
URL url=new URL(sSourceUrl);
URLConnection urlconn=url.openConnection();
urlconn.connect();
HttpURLConnection httpconn=(HttpURLConnection)urlconn;
HttpResult=httpconn.getResponseCode();
if(HttpResult!=HttpURLConnection.HTTP_OK)
{
}
else
{
InputStreamReader isr =
new InputStreamReader(httpconn.getInputStream(),"GB2312");
BufferedReader in = new BufferedReader(isr);
String inputLine;
if(!sDestDir.endsWith("/"))sDestDir+="/";
FileOutputStream fout = new FileOutputStream(sDestDir+sHtmlFile);
while ((inputLine = in.readLine()) != null)
{
fout.write(inputLine.getBytes());
}
in.close();
fout.close();
}
}
public static void main(String[] args) {
try {
convert2Html("http://www.163.com/", "C:/", "163.html");
} catch (IOException e) {
e.printStackTrace();
}
}
}
写简单点 原先写复杂了 有些朋友没看懂 这次把163读到C盘去