AWS Code Sample
Catalog demonstrates how to list objects within an Amazon S3 bucket.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package aws.example.s3; import; import; import; import; import java.util.List; /** * List objects within an Amazon S3 bucket. * * This code expects that you have AWS credentials set up per: * */ public class ListObjects { public static void main(String[] args) { final String USAGE = "\n" + "To run this example, supply the name of a bucket to list!\n" + "\n" + "Ex: ListObjects <bucket-name>\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String bucket_name = args[0]; System.out.format("Objects in S3 bucket %s:\n", bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); ListObjectsV2Result result = s3.listObjectsV2(bucket_name); List<S3ObjectSummary> objects = result.getObjectSummaries(); for (S3ObjectSummary os: objects) { System.out.println("* " + os.getKey()); } } }

Sample Details

Service: s3

Author: soo-aws

Type: full-example

On this page: