[英]How can I get my inputstream result of a http request outside the string buffer input loop
I'm using openstreetmap I can only see the inputstream inside the while loop 我正在使用openstreetmap我只能在while循环中看到输入流
Here's my code inside the initialize of the javafx Controller: 这是我在javafx Controller的初始化中的代码:
try {
URL myurl;
myurl = new URL("https://nominatim.openstreetmap.org/search?q=The+White+House,+Washington+DC&format=json&addressdetails=1");
URLConnection yc = myurl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null)
response.append(inputLine);
} catch (IOException ex) {
Logger.getLogger(WeatherUpdateController.class.getName()).log(Level.SEVERE, null, ex);
}
I am trying to get the StringBuffer inside a string variable so I can search it. 我正在尝试将StringBuffer放入字符串变量中,以便进行搜索。
Use StringBuffer#toString()
like so: 像这样使用StringBuffer#toString()
:
String str = response.toString();
Please note that you can use StringBuilder
instead if you don't need synchronization. 请注意,如果不需要同步,则可以改用StringBuilder
。 Source here 来源在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.