我使用JAVA编写此代码以从URL获取数据,它可以正常工作,但我困惑如何在while循环中从结果中获取第二个数据,
public static void main(String[] args) throws Exception {
// TODO code application logic here
URL link = new URL("http://192.168.1.5");
try (BufferedReader in = new BufferedReader(
new InputStreamReader(link.openStream()))) {
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
}
}
The Resuslt : Records:60 Counter:3,0:in,1:out,2:inside 2019/04/22 16:37:00,1797,1774,23 -------> I Just Want take This Result 2019/04/22 16:36:00,1797,1774,23 2019/04/22 16:35:00,1797,1774,23 2019/04/22 16:34:00,1797,1774,23 2019/04/22 16:33:00,1797,1774,23
答案 0 :(得分:-1)
尝试使用lines()
BufferReader lines转换为Stream,然后调用skip(1)
跳过第一个条目,并在findFirst
Stream findFirst之后调用,后者返回可选的值或为空。
像这样的东西:line = in.lines().skip(n).findFirst().get();
通过,这里已经有很多类似的问题与答案。例如: