0

考虑下面的代码,它允许我从 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 代码删除它?

4

1 回答 1

1

首先桶必须是空的。

然后你可以这样做:

storage.buckets().delete(Properties.bucketId).execute()

其中存储为 com.google.api.services.storage

我希望它有帮助!:)

于 2017-07-24T12:19:23.327 回答