工具类
程序员文章站
2022-03-03 10:26:53
...
package zjq.com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Gjb {
public static String getJson(String urlString){
try {
URL url=new URL(urlString);
try {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
int responseCode = urlConnection.getResponseCode();
if (responseCode==200){
InputStream inputStream = urlConnection.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder=new StringBuilder();
String a="";
String b="";
while ((a=reader.readLine())!=null){
b+=a;
}
return b;
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
}
上一篇: 文件选择器
下一篇: java的一些小方法