想实现下保存网页,试了下百度可以,打开来没有问题,但试了试url如果是www.google.com.hk,打开来就是乱码。。。不知道怎么解决
学java没多久。。新手求教。。
以下是java代码
public static void savePage(URL url) throws IOException, ParserException, IllegalArgumentException{
InputStream is = url.openStream();
int i;
String title = HTMLHelper.getTitle(url);
String file = url.getFile().trim();
String host = url.getHost().trim();
String filename = title+"("+url.getHost()+file+")";
FileOutputStream fos = new FileOutputStream("Pages\\"+filename+".html");
do{
i = is.read();
fos.write(i);
}
while(i!=-1);
is.close();
fos.close();
System.out.println("Success!The filename is:"+filename+".html");
}