Download an object to a file

Note: This example assumes that the Bucket sample exists.

Example: Download an Object from a Bucket to a File using the s3Client.getObject() method

AmazonS3 s3Client = new AmazonS3Client();
s3Client.setEndpoint("https://systemname.example.com");

GetObjectRequest request = new 1
GetObjectRequest( 2
"sample", 3
"myFile" 4
);

s3Client.getObject( 5
request, 6
new File("retrieved.txt") 7
);

1 Create a new request to get an object.
2 Request the object by identifying…
3 The sample Bucket
4 The myFile Object
5 Write the contents of the Object…
6 Using the request that was just created
7 To write to a new file called retrieved.txt