java - Read large file data using buffered reader in android -


hi want read large remote file string using buffered reader.but got half data of remote file.

        bufferedreader reader = new bufferedreader(new inputstreamreader(                 inputstream),8*1024);          stringbuilder sb = new stringbuilder(999999);         string line;          while ((line = reader.readline()) != null) {             log.e("line ",line);             sb.append(line + "\n");         }         is.close();         json = sb.tostring();         log.e("content: ", sb.tostring()); 

how full data of remote file?

it seems there nothing wrong code can try way:

private string receivedata(inputstream inputstream){          stringbuilder sb = null;         bufferedreader bufferedreader = new bufferedreader(new inputstreamreader( inputstream),8*1024);         sb = new stringbuilder();         string str;         int numread = 0;          try {             if (bufferedreader!=null) {                 if (bufferedreader.ready()) {                      try {                         while ((numread = bufferedreader.read()) >= 0) {                              //convert asci char , string                             str = string.valueof((char) numread);                              if ((str != null)&& (str.tostring() != "")) {                                  sb.append(str);                             }                              if (!bufferedreader.ready()){                                 //no more characters read                                 break;                             }                         }                     } catch (ioexception e) {                         e.printstacktrace();                     } catch (exception e) {                         e.printstacktrace();                     }                      //loop exited, check null                     if (sb != null) {                         return sb.tostring();                     }                 }             }         }         catch (exception e) {             e.printstacktrace();         }         return "";     } 

hope helped.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -