How to read data from URL in java code examples
public String getURLData(String realPath, String actionUrl){
StringBuffer buf=new StringBuffer();
try{
URL myurl = new URL(actionUrl);
URLConnection con = myurl.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
buf.append(inputLine);
}
in.close();
buf=new StringBuffer(buf.toString());//change special character in data
}
catch(java.net.ConnectException e1){
e1.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
return buf.toString();
}
StringBuffer buf=new StringBuffer();
try{
URL myurl = new URL(actionUrl);
URLConnection con = myurl.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
buf.append(inputLine);
}
in.close();
buf=new StringBuffer(buf.toString());//change special character in data
}
catch(java.net.ConnectException e1){
e1.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
return buf.toString();
}
Comments
Post a Comment