文件下載分chunk寫

文件下載

final OutputStream output = response.getOutputStream();
byte[] data = ...
output.write(data);

分chunk下載

public static void writeChunked(final byte[] data, final OutputStream output)
            throws IOException {
        if (data != null) {
            int bytes = data.length;
            int offset = 0;
            while (bytes > 0) {
                int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
                output.write(data, offset, chunk);
                bytes -= chunk;
                offset += chunk;
            }
        }
    }

想獲取最新內容,請關注微信公衆號
圖片描述微信

相關文章
相關標籤/搜索