AWS S3 Java 开发工具包 - 下载文件帮助
2022-09-01 01:42:15
以下代码仅适用于从 S3 中的存储桶下载文本文件。这不适用于映像。是否有更简单的方法来使用 AWS 开发工具包管理下载/类型?文档中包含的示例并不明显。谢谢!
AWSCredentials myCredentials = new BasicAWSCredentials(
String.valueOf(Constants.act), String.valueOf(Constants.sk));
AmazonS3Client s3Client = new AmazonS3Client(myCredentials);
S3Object object = s3Client.getObject(new GetObjectRequest("bucket", "file"));
BufferedReader reader = new BufferedReader(new InputStreamReader(
object.getObjectContent()));
File file = new File("localFilename");
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
while (true) {
String line = reader.readLine();
if (line == null)
break;
writer.write(line + "\n");
}
writer.close();