gpt4 book ai didi

java - 最后一行仅在 Java 中部分打印

转载 作者:行者123 更新时间:2023-11-29 07:58:41 25 4
gpt4 key购买 nike

我有一些比较两个文件的 java 代码。当它在特定行上找到相似的数字时,它会将该行打印到一个新文件中。这似乎工作了很长一段时间......直到我认为是最后一行。该行只会部分打印。我认为这可能是因为代码后面的“中断”,但我在谷歌上环顾四周,不确定是否有任何答案真的相关。这是一些我认为相关的代码:

Read in files
while the line isn't null...
Parse files
Write a header
Some comparisons
while (!input.startsWith("#") && !input.startsWith("P")) {
prse = input.split("\t");//split the file by tabs
pos = prse[7];
poson = prse[8];
pos = Integer.parseInt(poson);
if (cnt < num.size()) { //if we haven't exceeded an array
if (num.get(cnt).equals(pos)) { //if the first number is the same
if (cnt2 < posstart.size()) { //if we haven't exceeded another array
end = Integer.parseInt(posend.get(cnt2)); //change to int
start = Integer.parseInt(posstart.get(cnt2));//change to int
if (pos < start) { //if it is less then the starting pos then it can't fall within
break; //so break
}
if (pos < end && pos > start) {//I am trying to see if a number falls within the range of numbers from a separate file
out1.write(input + "\n"); //If it does: This is where I am writing out the line
break; //if I remove this break the program hangs here
} else {
cnt2++; //if it wasn't the same, add
}
}
} else {
cnt++; //if it was the same move to the next one
cnt2 = 0; //reset this number
break; //go back to beginning
}
} else {
break;
}

所以这段代码在大约 6500 行的时候完美运行,但是它突然切断了最后一行:

Blah    B   6   5   8   C   5   X   6
Blah A 0 1 4 C 2 X 7
Blah B 3 5 9 C 5 X 6
Blah B 0 9 4

有谁知道我可以添加什么来阻止最后一行突然中断?我知道在 BASH 中你可以指定它等待......但我对 java 等价物感到困惑,希望有人可以为我推荐一个并帮助更好地解释它。

最佳答案

为了得到答案(直到 Carl 提出他的问题)我将继续回答

did you close the outputstream? maybe you need to call the flush method. – Carl

他是对的。我没有。傻我。

关于java - 最后一行仅在 Java 中部分打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15930558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com