简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM