Check if bucket exists
Updated at:2025-11-03
Users can determine whether a bucket exists using the following code or with reference to Complete Example.
Java
1public void doesBucketExist (BosClient client, String bucketName) {
2 // Retrieve bucket existence information
3 // Specify the bucket name
4 boolean exists = client.doesBucketExist(bucketName);
5 // Output result
6 if (exists) {
7 System.out.println("Bucket exists");
8 } else {
9 System.out.println("Bucket not exists");
10 }
11}
Note: If the bucket is not null (that is, there are objects in the bucket), the bucket cannot be deleted. The bucket must be emptied before it can be deleted successfully.
