Skip to content

Commit 760ea21

Browse files
authored
Fix storage bucket listing sample in README.md
#2301
1 parent bf78f32 commit 760ea21

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

google-cloud-storage/README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,19 @@ String blobContent = new String(blob.getContent(), UTF_8);
113113
```
114114

115115
#### Listing buckets and contents of buckets
116-
Suppose that you've added more buckets and blobs, and now you want to see the names of your buckets and the contents of each one. Add the following imports:
117-
118-
```java
119-
import java.util.Iterator;
120-
```
121-
122-
Then add the following code to list all your buckets and all the blobs inside your newly created bucket.
116+
Suppose that you've added more buckets and blobs, and now you want to see the names of your buckets and the contents of each one. Add the following code to list all your buckets and all the blobs inside each bucket.
123117

124118
```java
125119
// List all your buckets
126-
Iterator<Bucket> bucketIterator = storage.list().iterateAll();
127120
System.out.println("My buckets:");
128-
while (bucketIterator.hasNext()) {
129-
System.out.println(bucketIterator.next());
130-
}
131-
132-
// List the blobs in a particular bucket
133-
Iterator<Blob> blobIterator = bucket.list().iterateAll();
134-
System.out.println("My blobs:");
135-
while (blobIterator.hasNext()) {
136-
System.out.println(blobIterator.next());
121+
while (Bucket bucket : storage.list().iterateAll()) {
122+
System.out.println(bucket);
123+
124+
// List all blobs in the bucket
125+
System.out.println("Blobs in the bucket:");
126+
for (Blob blob : bucket.list().iterateAll()) {
127+
System.out.println(blob);
128+
}
137129
}
138130
```
139131

0 commit comments

Comments
 (0)