2017-06-19 75 views
0

考慮下面的代碼,讓我創建從Java水桶......如何從Java中刪除Google雲端平臺中的存儲分區?

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代碼?

回答

1

首先桶必須是空的。

然後,你可以這樣做:。

storage.buckets()刪除(Properties.bucketId).execute()

是在存儲com.google.api.services.storage

我希望能幫助到你! :)