1

2 つのファイルを比較する 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の同等物に戸惑い、誰かが私に提案して、もう少し詳しく説明してくれることを望んでいました。

4

2 に答える 2

4

答えを得るために(カールが立ち上がるまで)私は先に進んで答えるつもりです

出力ストリームを閉じましたか?おそらく、flush メソッドを呼び出す必要があります。– カール

彼は正しかったです。私はしていませんでした。愚かな私。

于 2013-04-10T17:44:05.400 に答える