[英]GCP storage - read data from mongo db and write it into to file GCP bucket
[英]How read XLS file from gcp bucket
我有桶XLS
文件,我必须提取文件并读取流中的数据并处理数据。 我使用了CSV
文件,这是我的代码:
try (ReadChannel reader = storage.reader(bucketName, fileName)) {
ByteBuffer bytes = ByteBuffer.allocate(BUFFER_SIZE);
while (reader.read(bytes) > 0) {
bytes.flip();
// outChannel.write(bytes);
set(new String(bytes.array(), "UTF-8"), fileName);
bytes.clear();
}
}
我想这可能就是你要找的。 GCS 输入通道
GcsService gcsService = GcsServiceFactory.createGcsService();
GcsFilename fileName = new GcsFilename("TestBucket", "Test1.xlsx");
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
InputStream inputStream = Channels.newInputStream(readChannel);
我还发现了一个可能对您有所帮助的有趣解决方法,在这个答案中,您有一段代码可以将所有 excel 文件转换为 CSV,以便您可以正常操作它们。
编辑:错误在那里,因为它没有被初始化。 看看我的代码编辑。
在你的情况下,据我所知,你可能需要使用“ OutputChannel ”而不是“InputChannel”,但它是相同的概念。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.