[英]While loop with buffered reader readline only loops once and goes into infinite loop
Am new to java and i have a program that's supposed to read through a file using a bufferred read and do some stuffs with the result. Java的新手,我有一个程序应该使用bufferedred读取来读取文件,并对其结果做一些处理。 The program is that it only reads the first and line and goes into an infinite loop. 该程序是,它仅读取第一行和第二行并进入无限循环。 I have tried different files but am getting the same result. 我尝试使用不同的文件,但得到的结果相同。
private void readingFile(){
DataType type;
String line;
Log log = new Log(writeFile);
try(BufferedReader reader = Files.newBufferedReader(Paths.get(readFile))){
while ((line = reader.readLine()) != null){
if (line.charAt(0) == '#' || line.charAt(0) == '/') {
continue;
}
String[] lineArray = line.split(" - ", 2);
String one = lineArray[0];
String two = lineArray[1];
type = new DataType(one, two);
queue.put(type);
log.readMessage(one, two);
}
}
catch (Exception ex){
System.out.println(ex.getClass().getSimpleName() + "-" +
ex.getMessage());
}
}
What does the statement: 声明是什么:
log.readMessage(one, two);
do? 做? Does it return in a finite amount of time? 它会在有限的时间内返回吗?
Try and run your program again while removing the following lines: 请尝试并重新运行您的程序,同时删除以下几行:
String[] lineArray = line.split(" - ", 2);
String one = lineArray[0];
String two = lineArray[1];
type = new DataType(one, two);
queue.put(type);
log.readMessage(one, two);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.