1

I would like to connect to a Website, filter some content and then put it in a String but I don´t know how to do this.

public void zahlenLaden (View view) throws Exception { 

    URL oracle = new URL("http://www.blabla.de");
    URLConnection yc = oracle.openConnection();
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            yc.getInputStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null) {
  //What I have to write here?
    }

3 Answers 3

2

Declare a String to output to before the while loop:

String output = "";

Then just append to that String in each iteration:

output += inputLine + "\n"; (don't forget the omitted newline)
Sign up to request clarification or add additional context in comments.

Comments

2
StringBuilder sb = new StringBuilder();

 while ((inputLine = in.readLine()) != null) {
      sb.append(inputLine + "\n");

    }

then just do sp.toString();

Comments

0

Nikola's answer is OK, just an improvement on the use of StringBuilder:

StringBuilder sb = new StringBuilder();

 while ((inputLine = in.readLine()) != null) {
      sb.append(inputLine).append("\n");
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.