2017-02-22 1 views
0

내 앱이 인터넷에 연결되어 페이지를 스크럽하여 이미지와 텍스트 같은 것을 얻도록 HTML을 얻습니다. 그러나 일부 구두점이 실제로 유니 코드 10 진수 코드로 변환되는 것을 보았습니다. 어쨌든이를 막으려 고합니다.구두점을 유니 코드로 변환하는 InputStream

public class DownloadPage extends AsyncTask<String, Void, String> { 

    public interface PageResponse { 
     void processFinish(String output); 
    } 

    private PageResponse delegate = null; 

    public DownloadPage(PageResponse delegate){ 
     this.delegate = delegate; 
    } 

    @Override 
    protected String doInBackground(String... urls) { 
     URLConnection connection; 
     try { 
      URL url = new URL(urls[0]); 

      connection = url.openConnection(); 

      String html; 
      InputStream inputStream = connection.getInputStream(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 
      StringBuilder str = new StringBuilder(); 
      String line; 
      while ((line = reader.readLine()) != null) { 
       str.append(line); 
      } 
      inputStream.close(); 
      html = str.toString(); 

      return html; 

     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
      return "Failed"; 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return "Failed"; 
     } 
    } 

    @Override 
    protected void onPostExecute(String s) { 
     super.onPostExecute(s); 
     delegate.processFinish(s); 
    } 
} 

이것은 https://www.looemusic.co.uk/news/에서 정보를 얻는 페이지입니다. 당신은 문제가 당신의 InputStreamReader의 캐릭터 세트 당신의 InputStream 함께, 아닌 HTML, 당신은 설정할 수 자체를 렌더링해야합니다 경우

This is what comes up with this code.

답변

0

:

new InputStreamReader(inputStream, Charset.UTF-8); 

이 캐릭터 세트는 java.nio의에서입니다 .charset.

이것이 실패하면 클라이언트의 인코딩에 문제가 없는지 확인할 수 있습니다. HTML 파일에서이 태그를 넣어 : HTML 4

<meta charset="UTF-8"> 

가 : 당신이 다음 UTF-8 대신 다른 문자 집합을 사용하려면

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 

단지를 변경 HTML 5

코드의 이름!

+0

Charset.UTF-8을 좋아하지 않습니다. 옵션이 아닙니다. –

관련 문제