I want to get the source code of a webpage. I am using HttpConnection
following is my code..
HttpConnection c = null;
InputStream dis = null;
StringBuffer raw = new StringBuffer();
try {
c = (HttpConnection)Connector.open(txtUrl.getText().toString());
int len = 0;
int size = 0;
dis = c.op开发者_Go百科enInputStream();
byte[] data = new byte[256];
while ( -1 != (len = dis.read(data)) ){
raw.append(new String(data, 0, len));
size += len;
}
System.out.println("Html source"+raw.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Exception " +e);
}
finally {
if (dis != null)
try {
dis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Exception " +e);
}
if (c != null)
try {
c.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Exception " +e);
}
}
At this line dis = c.openInputStream();
i am getting error as source not found - datagramProtocol(ConnectionBase).receive(Datagram).
Where I am going wrong please correct me..
You should probably read the API documentation for javax.microedition.io.HttpConnection and implement your input routine as recommended there.
精彩评论