如何从 java 中删除 Google Cloud Platform 中的存储桶?
How can I delete a bucket in Google Cloud Platform 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());
}
}
问题是:如何使用 java 代码删除它?
首先桶必须是空的。
那么你可以这样做:
storage.buckets().删除(Properties.bucketId).执行()
其中存储是 com.google.api.services.storage
希望对您有所帮助! :)
考虑下面的代码,它允许我从 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());
}
}
问题是:如何使用 java 代码删除它?
首先桶必须是空的。
那么你可以这样做:
storage.buckets().删除(Properties.bucketId).执行()
其中存储是 com.google.api.services.storage
希望对您有所帮助! :)