我是java的新手,我有一个程序应该通过缓冲读取读取文件,并对结果做一些事情。程序是它只读取第一个和第一行并进入无限循环。我尝试了不同的文件,但得到了相同的结果。
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());
}
}
答案 0 :(得分:0)
声明是什么:
log.readMessage(one, two);
做什么?它会在有限的时间内返回吗?
尝试重新运行程序,同时删除以下行:
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);