0

I am trying to capture the text of a page and then display it in my application.   But when I run the program does not display the text. The site is http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=1

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_examplebackground);

    try {
        URL url = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=1"); 
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

        String inputLine="";
        String inputText = ""; 
        while ((inputLine = in.readLine()) != null) {
            inputText = inputText + inputLine;
        }

        System.out.println(inputText);
    }catch(MalformedURLException t){
        System.out.println("error de url");
    } catch(Throwable t){
        System.out.println("error de bufffer");
    }
}
Dhruvisha
  • 2,538
  • 1
  • 21
  • 31

2 Answers2

0

You the formats of text are different. You need to encode both of them in UTF format.

Encode it something like:

String data = URLEncoder.encode("data", "UTF-8");

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Anand Kumar
  • 66
  • 2
  • 8
0

Don't use readLine if InputStream does not provides new line character, or, it will be blocked (waiting for new line character) there.

I suggest use apache-commons-io library to read text from InputStream

String charset = "UTF-8";
inputText = org.apache.commons.io.IOUtils.toString (url, charset);
LiuYan 刘研
  • 1,614
  • 1
  • 16
  • 29