这是我写的一个函数贴出来
public String urlCon(String input) {
try {
URL url = new URL(PATH + input);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(8000);
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
OutputStream outputStream = connection.getOutputStream();
outputStream.flush();
connection.getResponseCode();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder response = null;
response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println(response);
Log.i("返回的数据是 ", response.toString());
return response.toString();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (ProtocolException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
};
return null;
}
这个函数的返回值是response.toString();因为在TRY里面所以还要返回一个null,这样没错吧?然后现在有另一个函数 假设这个函数里面其中一个方法()里面的参数需要的是 这个函数的返回值response.toString()的值,请问这里要怎么实现呢?