将AWS s3文件读取为Java代码

我试图从AWS s3读取文件到Java代码:

  File file = new File("s3n://mybucket/myfile.txt");

FileInputStream fileInput = new FileInputStream(file);

然后我得到一个错误:

java.io.FileNotFoundException:s3n:/mybucket/myfile.txt(无此类文件或目录)位于java.io.FileInputStream.open(本地方法)处java.io.FileInputStream。(FileInputStream.java:146)


有没有办法从AWS s3打开/读取文件?非常感谢!

回答:

Java的“文件”类无法理解S3的存在。这是从AWS文档中读取文件的示例:

AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());        

S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, key));

InputStream objectData = object.getObjectContent();

// Process the objectData stream.

objectData.close();

以上是 将AWS s3文件读取为Java代码 的全部内容, 来源链接: utcz.com/qa/425970.html

回到顶部