package app; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; public class TestURL { public static void main(String[] args) throws IOException { String host = "172.28.138.13"; String port = "8080"; setProxy(host, port); // URL url = new URL("http://www.google.co.jp/"); // URL url = new URL("http://www.yahoo.co.jp/"); URL url = new URL("http://www.baidu.com/"); // URL url = new URL("http://localhost:8080/fileUpDownload/"); InputStream is = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "gbk")); // BufferedReader br = new BufferedReader(new // InputStreamReader(is,"UTF-8")); // BufferedReader br = new BufferedReader(new // InputStreamReader(is,"MS932")); String line = null; while ((line = br.readLine()) != null) { // System.out.println(new String(line.getBytes("UTF-8"), "MS932")); System.out.println(line); } // System.out.println(url.getContent()); } /** * プロクシサーバーを設定します。 * * @param host * サーバー * @param port * ポート */ public static void setProxy(String host, String port) { System.setProperty("proxySet", "true"); System.setProperty("proxyHost", host); System.setProperty("proxyPort", port); } }