[英]How can I delete a bucket in Google Cloud Platform from java?
Consider the below code which allows me to create a bucket from Java... 考虑下面的代码,它允许我从Java创建存储桶...
package com.lscale.gcp.test1;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
public class CreateBucket {
public static void main(String... args) throws Exception {
// Instantiates a client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name for the new bucket
String bucketName = Properties.bucketId; // "my-new-bucket";
// Creates the new bucket
Bucket bucket = storage.create(BucketInfo.of(bucketName));
System.out.printf("Bucket %s created.%n", bucket.getName());
}
}
The question is: how can I delete it, using java code? 问题是:如何使用Java代码将其删除?
First of all the bucket must be empty. 首先,存储桶必须为空。
Then you can do: 然后,您可以执行以下操作:
storage.buckets().delete(Properties.bucketId).execute() storage.buckets()。delete(Properties.bucketId).execute()
where storage is com.google.api.services.storage 存放com.google.api.services.storage的位置
I hope it helps! 希望对您有所帮助! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.