不能用 url.openStream 下載 yahoo 中文
想請教一下我用 url class 下載一些 yahoo 中文網頁, 但不知為何不能顯示中文...
環境: os=windows xp with sp2, locale=hong kong, jdk=1.4.1, ide=eclipse3.0
code:
public class DownloadPage {
public static void main(String[] args) {
DownloadPage dp = new DownloadPage();
dp.download("http://hk.search.yahoo.com/search?p=stupid+yahoo&fl=0&vc=&x=wrt&meta=rst=hk&ei=BIG5&n=10");
}
public void download(String searchStr) {
try {
URL url = new URL(searchStr);
Reader r = new BufferedReader(new InputStreamReader(url.openStream(), "BIG5"));
Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("c:\\temp\\a.html"), "UTF-8"));
char[] buffer = new char[4096];
int len;
while((len = r.read(buffer)) != -1)
w.write(buffer, 0, len);
r.close();
w.flush();
w.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// end code
可下載 c:\temp\a.html 檔案, 但不能顯示中文, 謝謝高手幫忙!