[英]How can I skip the next Variable that is inserted In the same line?
I put 1, 2, 3 then I want only 1 and 3 to be view. 我输入1、2、3,然后只希望查看1和3。
BufferedReader br = new BufferedReader (new FileReader("medicine.txt"));
while(line= br.readLine() != null) {
System.out.print("line+"br.readLine()):
}
Maybe you should split your line with the character ',' 也许您应该用字符','分隔行
while(line = br.readLine() != null) {
String[] splittedLine = line.split(",");
System.out.println(splittedLine[0] + "-" + splittedLine[1]);
}
You can solve this in a myriad of ways but if you always want to skip "2", something like this should work: 您可以通过多种方式解决此问题,但是如果您始终想跳过“ 2”,则应执行以下操作:
while(line = br.readLine() != null) {
if (line.equals("2")) {
continue;
}
System.out.print("line: " + line);
}
您可以使用计数器并检查计数器是否到达您的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.