Java nosuch从GCP Bucket读取文件的方法
我正试图使用以下代码从Google云存储桶中读取一个文件Java nosuch从GCP Bucket读取文件的方法,java,google-cloud-platform,Java,Google Cloud Platform,我正试图使用以下代码从Google云存储桶中读取一个文件 Blob blob = storage.get(BlobId.of(Constants.GCS_BUCKET, srcFilename)); printBlob(blob.reader()); private void printBlob(ReadChannel reader) { try { WritableByteChannel outChannel = Channels.newChannel(System.o
Blob blob = storage.get(BlobId.of(Constants.GCS_BUCKET, srcFilename));
printBlob(blob.reader());
private void printBlob(ReadChannel reader) {
try {
WritableByteChannel outChannel = Channels.newChannel(System.out);
ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);
while (reader. read(bytes) > 0) {
bytes.flip();
outChannel.write(bytes);
bytes.clear();
}
}
catch (Exception e) {
}
}
执行reader.read(字节)
时,代码抛出此异常
[INFO] GCLOUD: Caused by:
[INFO] GCLOUD: java.lang.NoSuchMethodError: com.google.api.services.storage.Storage$Objects$Get.setReturnRawInputStream(Z)Lcom/google/api/client/googleapis/services/AbstractGoogleClientRequest;
[INFO] GCLOUD: at com.google.cloud.storage.spi.v1.HttpStorageRpc.createReadRequest(HttpStorageRpc.java:658)
[INFO] GCLOUD: at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:693)
[INFO] GCLOUD: at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
[INFO] GCLOUD: at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
解决了。
需要使用依赖项
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core-http</artifactId>
<version>1.91.0</version>
</dependency>
com.google.cloud
谷歌云核心http
1.91.0
如果使用1.90.0,它会崩溃。它也会在下载文件时出现->blob.downloadTo(path.get(“/tmp/”+srcFilename));你是否遵循任何教程?