0
       int count = 0;
        byte[] buffer = new byte[8192]; // more if you like but no need for
        int j = length_img % 8192;
        int value = length_img - j;
        int incre = 0;// it to be the entire file size

        for (int i = 0; i < (value / 8192) + 1; i++) {

            if (length_img == incre + j) {
                buffer = new byte[j];
                int pair = dataInputStream.read(buffer);
                System.out.print("i am here for last chunk" + buffer.length
                        + "value of j is" + j + "incre value is" + incre
                        + "the value of i is" + i
                        + "and the value of count is" + pair);

                image0OutFile.write(buffer, 0, pair);
                break;
            }

            else {
                count = dataInputStream.read(buffer);
                image0OutFile.write(buffer, 0, count);
                incre += 8192;
            }
        }

これはいくつかの問題がある部分です。私はこの出力を取得しています length_img : 3147850 [B@72d86c58 i は最後のチャンクのためにここにいますj の値は 2122incre の値は 3145728i の値は 384 で、count の値は 496bublo ... の値に気付いた場合ペアは 2122 である必要がありますが、代わりに 496 であるため、ファイルが破損しています。

4

2 に答える 2

2

次を閉じる必要がありますFileOutputStream

image0OutFile.close

これにより、最終部分がファイルにフラッシュされます。または、次のように呼び出すこともできます。

image0OutFile.flush()

でも前作がオススメ。また、開いたストリームは常に閉じる必要があります。

于 2013-03-23T09:56:23.237 に答える
0

ストリームを常に閉じる

最初にコードをTry catchブロックに入れます。ストリームをブロックで閉じFinallyます。

finally{
        image0OutFile.close();
      }

そして、フラッシュに行かないでください。クローズが呼び出されると、自動的にフラッシュが発生します。

于 2013-03-23T09:58:40.280 に答える