6.2. 从流传输的大消息中读取
要从大消息中读取,请使用 BytesMessage.readBytes()
方法。以下示例从信息中读取字节并将其写入文件:
示例:从流传输的大消息中读取
BytesMessage message = (BytesMessage) consumer.receive(); File outputFile = new File(outputFilePath); OutputStream outputStream = new FileOutputStream(outputFile); int numRead; byte buffer[] = new byte[1024]; for (int pos = 0; pos < message.getBodyLength(); pos += buffer.length) { numRead = message.readBytes(buffer); outputStream.write(buffer, 0, numRead); }