2025年Utils_utility是什么意思

Utils_utility是什么意思package com example week import java io InputStream import java net HttpURLConne import java net URL Created by 生哥 on 2017 12 2 public class NewUtils private

package com.example.week;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
* Created by 生哥 on 2017/12/2.
*/

public class NewUtils {
private static final String JSON_URL = "https://api.tianapi.com/wxnew/";
private URL url;
private HttpURLConnection urlConnection;
private String data = "";

public String getJsonUrl(final String pa) {
try {
url = new URL(JSON_URL + pa);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(5000);
urlConnection.setReadTimeout(5000);
int responseCode = urlConnection.getResponseCode();
if (responseCode == 200) {
InputStream inputStream = urlConnection.getInputStream();
byte[] b = new byte[1024];
int len = 0;
while ((len = inputStream.read(b)) != -1) {
String str = new String(b, 0, len);
data += str;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return data;

}

}
编程小号
上一篇 2025-07-09 13:40
下一篇 2025-10-03 23:17

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/115941.html