Sample code for 30+ languages & platforms
Java

S3 Download String Object

See more Amazon S3 Examples

Demonstrates how to download a text file (i.e. object) from the Amazon S3 service directly into an in-memory string variable.

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 us-east-1 region.
        http.setAwsRegion("us-east-1");

        String bucketName = "chilkat-test-bucket";

        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());
        }
    }
}