Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从java中删除Google云平台中的bucket?_Java_Gcp - Fatal编程技术网

如何从java中删除Google云平台中的bucket?

如何从java中删除Google云平台中的bucket?,java,gcp,Java,Gcp,考虑下面的代码,它允许我从Java创建一个bucket 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 Crea

考虑下面的代码,它允许我从Java创建一个bucket

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代码删除它?

首先,bucket必须为空

然后你可以做:

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

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

我希望有帮助!:)