How to read Specific data from InputStream object, While i am using HttpUrlConnection object to make connection. I want to READ and POST data ,for example , i want to read specific Tag data , like and so on. like wise i want to Post also.
public class Test {
public static void main(String[] args) throws Exception {
HttpsURLConnection con = (HttpsURLConnection) new URL("some URL ...")
.openConnection();
// reading data from connection
InputStream in = new BufferedInputStream(con.getInputStream());
System.out.println(readStream(in));
}
private static String readStream(InputStream is) {
try {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
int i = is.read();
while(i != -1) {
bo.write(i);
i = is.read();
}
return bo.toString();
} catch (IOException e) {
return "";
}
}
}
please help..
Try this I was getting JSONObject in my case :
static InputStream is = null;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
使用jsoup http://jsoup.org它具有处理html所需的工具。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.