How to get content of a URL and to read it in a android java application using eclipse -


//following code works fine read's source code content, need read content help.//

package t.n.e;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.net.malformedurlexception; import java.net.url;  import org.xml.sax.parser;  import android.app.activity; import android.os.bundle; import android.widget.edittext;    public class urlgettingproject extends activity {     private edittext t1;      public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          t1 = (edittext)findviewbyid(r.id.t1);         stringbuilder content = new stringbuilder();           try {             url url = new url("http://10.0.22.222:8080/savename.jsp?first=12&second=12&work=min");             bufferedreader in = new bufferedreader(new inputstreamreader(url.openstream()));             string str;             while ((str = in.readline()) != null) {                 content.append(str +"\n");                 t1.settext(content);             }             in.close();         } catch (malformedurlexception e){         } catch (ioexception e) {             e.printstacktrace();         }      } } 

well, if need content, why won't simplify way:

    private inputstream openhttpconnection(string strurl)             throws ioexception {         urlconnection conn = null;         inputstream inputstream = null;         url url = new url(strurl);         conn = url.openconnection();         httpurlconnection httpconn = (httpurlconnection) conn;         httpconn.setrequestmethod("get");         httpconn.connect();         if (httpconn.getresponsecode() == httpurlconnection.http_ok) {             inputstream = httpconn.getinputstream();         }         return inputstream;     } 

and read stream?


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -