1

良い一日。Objective-CからJavaに切り替えて、URLの内容を通常どおり文字列に読み込もうとしています。たくさんの投稿を読んでも、それでもゴミが出ます。

public class TableMain {

    /**
     * @param args
     */
    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws Exception {
        URL url = null;
        URLConnection urlConn = null;

        try {
            url = new URL("http://svo.aero/timetable/today/");
        } catch (MalformedURLException err) {
            err.printStackTrace();
        }
        try {
            urlConn = url.openConnection();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    urlConn.getInputStream(), "UTF-8"));
            StringBuilder strB = new StringBuilder();
            String str;
            while (null != (str = input.readLine())) {
                strB.append(str).append("\r\n");
                System.out.println(str);
            }
            input.close();
        } catch (IOException err) {
            err.printStackTrace();
        }
    }
}

どうしたの?私はこのようなものを手に入れます

?? y ??'??)j1 ???-?q?E?| V ??、?? <9 ?? d?Bw(?э?n?v?)i?x ????? Z ???? q?MM3〜?????? G??љ??l?U3 "Y?] ???? zxxDx ???? t ^ ??? 5 ??? j? ?k ?? u?q?j6?^ t ??????? W ??????????〜????????? o6 /?|?8 ?? {? ?? O ???? 0?M> Z {srs ?? K ??? XV ?? 4Z‌ ??'?? n / ?? ^ ?? 4 ???? w + ????? e? ?????? [?{/ ??、?? WO ?????????。?。?x ??????? ^?rax ??]?xb ?? ‌ &amp; ?? 8; ?????} ??? h ???? H5 ???? v?e?0 ?????-????? g?vN

4

2 に答える 2

-1

HttpClientを使用するメソッドは次のとおりです。

 public HttpResponse getResponse(String url) throws IOException {
    httpClient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    return httpClient.execute(new HttpGet(url));
}


public String getSource(String url) throws IOException {
            StringBuilder sb = new StringBuilder();
            HttpResponse response = getResponse(url);
            if (response.getEntity() == null) {
                throw new IOException("Response entity not set");
            }
            BufferedReader contentReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            String line = contentReader.readLine();

            while ( line != null ){
                sb.append(line)
                  .append(NEW_LINE);
                line = contentReader.readLine();
            }
            return sb.toString();
    }

編集:utf-8を使用するように応答を編集しました。

于 2012-09-25T21:52:04.690 に答える
-1

これは次の結果です:

  1. UTF-8でエンコードされたデータをフェッチしています
  2. 指定されていませんが、Windowsシステムのコンソールに印刷していると思います

データは正しく受信および保存されていますが、印刷すると、宛先でロシア語のテキストをレンダリングできません。究極のディスプレイハンドラーが関連する文字をレンダリングできない限り、テキストをstdoutに単に「印刷」することはできません。

于 2012-09-25T22:13:17.170 に答える