Java: Why can't I output a String converted from StringBuffer to the console in it's entirety? -


when debug code below, in "variables" view, both response , this.response show entire 1,779 lines of streamed input http://www.google.com. if, however, want output this.response console system.out.println(this.response.tostring();, outputs last few lines.

initially thought limitation of string class. test copied 1,779 lines , assigned them test string variable. when output test string variable, output 1,779 lines console fine.

what missing both this.respponse , response show entire document, when go output either of them, last few lines?

public class classc {     private string url = "http://www.google.com";     private url url;     private httpurlconnection con;     private string response;     public static void main(string[] args) {         new classc();     }      public classc() {         try {             url = new url(url);             con = (httpurlconnection) url.openconnection();              inputstream = con.getinputstream();             bufferedreader rd = new bufferedreader(new inputstreamreader(is));             string line = null;             stringbuffer response = new stringbuffer();             while((line = rd.readline()) != null) {                 response.append(line);                 response.append('\r');                 system.out.println(response.tostring());             }             rd.close();             this.response = response.tostring();             system.out.println(this.response);          } catch (ioexception e) {             e.printstacktrace();         }      } } 

try \n instead of \r.

'\r' carriage return - returns caret start of line, doesn't start new line, overwriting current line (or parts of it).

e.g. system.out.println("abcde\rfghi") results in fghie.


Popular posts from this blog