2017-06-19 11 views
0

javaからGoogle Cloud Platformのバケットを削除するにはどうすればよいですか?

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からバケツを作成することができます以下のコードを考えてみましょう質問です:どのように私は、Javaコードを使用して、それを削除することができますか?

答えて

1

まず、バケツは空でなければなりません。

次に、あなたが行うことができます:。

storage.buckets()を削除(Properties.bucketId).execute()

ストレージがcom.google.api.services.storageです

Iそれが役に立てば幸い! :)