I'm writing an android app that requires that I retrieve the html code of a webpage and get and return specific elements. For some reason, the code seems to hang or take an unbelievably long time doing basic string operations.
URL url = new URL(link);
URLConnection urlConnection = url.openConnection();
InputStreamReader i = new InputStreamReader(
urlConnection.getInputStream());
BufferedReader in = new BufferedReader(i);
String check = "";
String html = "";
while((check = in.readLine()) != null)
html += check;
Takes minutes to complete on both the emulator and the device with university connection speeds. Whereas
URL url = new URL(link);
URLConnection urlConnection = url.openConnection();
InputStreamReader i = new InputStreamReader(
urlConnection.getInputStream());
BufferedReader in = new BufferedReader(i);
String check = "";
String html = "";
int p = 0;
while((check = in.readLine()) != null)
p++;
takes ~ 5 seconds and returns the correct number of lines in the html page. Why do the string operations take so long? Just for perspective, the page is about 4000 lines long.