You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Basic Bucket Interface
Deleting a Bucket (Java SDK)
Copy page
Download PDF
Deleting a Bucket (Java SDK)
A Bucket is the globally unique namespace in TOS, functioning as a data container used to store Object data. When you no longer need to retain a bucket (Bucket), you may delete it to avoid incurring additional charges. This document describes how to delete a specified bucket using the TOS Java SDK deleteBucket interface.​
Category​
  • Once a bucket is deleted, it cannot be recovered. Please proceed with caution.​
Prerequisites​
Before deleting a bucket, ensure that all data within the bucket has been removed.​
  • If versioning is enabled for the bucket, please ensure that all current and previous version objects within the bucket have been deleted. For detailed instructions, see Delete Object.​
  • If there are unmerged shards in the bucket, ensure that all shard data is deleted. For detailed instructions, see Delete Shard.​
  • If there are a large number of objects in the bucket, you can configure lifecycle rules to enable batch deletion of objects. For specific steps, see Configuring Lifecycle Rules.​
Code Example​
The following code demonstrates how to delete an empty bucket.​
​
import com.volcengine.tos.TOSV2;​
import com.volcengine.tos.TOSV2ClientBuilder;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.bucket.DeleteBucketInput;​
import com.volcengine.tos.model.bucket.DeleteBucketOutput;​
​
public class DeleteBucketExample {​
public static void main(String[] args) {​
String endpoint = "your endpoint";​
String region = "your region";​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY");​
String bucketName = "your bucket name";​
​
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try{​
DeleteBucketInput input = new DeleteBucketInput().setBucket(bucketName);​
DeleteBucketOutput output = tos.deleteBucket(input);​
System.out.println("deleteBucket succeed, " + output);​
} catch (TosClientException e) {​
System.out.println("deleteBucket failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
System.out.println("deleteBucket failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
System.out.println("deleteBucket failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Related documentation​
For API documentation on deleting a bucket, see DeleteBucket.​
Last updated: 2025.09.19 20:00:28