Fork me on GitHub

Programming Design Notes

Google App Engine java.net.URL 亂碼解決方法

| Comments

Google App Engine 使用 java.net.URL 讀取中文網頁資訊時會變成亂碼,解決方法在 new InputStreamReader 時指定網頁的編碼方式。
例如要讀取 hk.yahoo.com 的資訊:
URL url = new URL("http://hk.yahoo.com");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
這樣便不會出現亂碼。

相關書籍: Programming Google App Engine: Build and Run Scalable Web Apps on Google's Infrastructure (Animal Guide)Using Google App EngineBeginning Java Google App Engine