Vpn_talent
Vpn_talent

Reputation: 1436

How to use Amazon s3 path for listing amazon s3 folders in java

I am using Apache Spark for parsing files. I have Amazon S3 path s3n://my-bucket/amazone-folder/ how to list all files and sub folders using this path.

Upvotes: 0

Views: 160

Answers (1)

kosa
kosa

Reputation: 66637

AWS Java-SDK documentation has API details you could use for this purpose:

Provides an easy way to iterate Amazon S3 objects in a "foreach" statement. For example:

for ( S3ObjectSummary summary : S3Objects.withPrefix(s3, "my-bucket", "photos/") ) {
    System.out.printf("Object with key '%s'\n", summary.getKey());
}

The list of S3ObjectSummarys will be fetched lazily, a page at a time, as they are needed. The size of the page can be controlled with the withBatchSize(int) method.

And here is another tutorial explains how to work with AWS Java SDK

Upvotes: 1

Related Questions