android - How to read from .txt file -


i trying read text file present on server, file containing text "hello world" ,now want write text on textview . have imported required packages . in advance

 public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          textview tv = new textview(this);          try {             url updateurl = new url("http://--------------------/foldername/hello.txt");                             urlconnection conn = updateurl.openconnection();              inputstream = conn.getinputstream();             bufferedinputstream bis = new bufferedinputstream(is);             bytearraybuffer baf = new bytearraybuffer(50);              int current = 0;             while((current = bis.read()) != -1){                  baf.append((byte)current);             }               final string s = new string(baf.tobytearray());                  ((textview)tv).settext(s);               } catch (exception e) {         }     }; 

try function ....

 public static string convertstreamtostring(inputstream is) throws exception {         bufferedreader reader = new bufferedreader(new inputstreamreader(is));         stringbuilder sb = new stringbuilder();         string line = null;          while ((line = reader.readline()) != null) {             sb.append(line);         }          is.close();          return sb.tostring();     } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -