[Amazon S3] Listing Bucket contents programatically

A lot of us use Amazon S3 data to store data. Mostly we use some kind of browsers to view the data. Amazon provides a java sdk using which we can programatically access S3 contents. Lets see listing the contents in this post.

Initialisation code

AmazonS3 is the class provided by Amazon SDK which helps interfacing with S3. Here we use BaseAWSCredentials class and pass on Access Id and Secret key. There are alternative classes that can read credentials from properties files or from System properties.

We shall see two functions, the first one list all the folders to which the given access id and secret key pair has access to.