Sample code for 30+ languages & platforms
Java

Amazon S3 Download String from Bucket in Region

See more Amazon S3 Examples

Demonstrates how to download a text file (i.e. object) from an S3 bucket NOT in the us-east-1 region.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        // Insert your access key here:
        http.setAwsAccessKey("AWS_ACCESS_KEY");

        // Insert your secret key here:
        http.setAwsSecretKey("AWS_SECRET_KEY");

        // This bucket is in the eu-central-1 region.
        http.setAwsRegion("eu-central-1");

        String bucketName = "chilkateufrankfurt";

        String objectName = "fruit.xml";

        String charset = "utf-8";

        String fileContents = "";

        try {
            fileContents = http.s3DownloadString(bucketName, objectName, charset);
            // Success
            System.out.println(fileContents);
        } catch (ChilkatException e) {
            // Failed
            System.out.println(e.getLastErrorText());
        }
    }
}