Read AWS s3 File to Java code

I tried to read a file from AWS s3 to my java code:

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

Then I got an error: s3n:/mybucket/myfile.txt (No such file or directory) at Method) at

Is there a way to open/read a file from AWS s3? Thanks a lot!


The ‘File’ class from Java doesn’t understand that S3 exists. Here’s an example of reading a file from the AWS documentation:

AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());        
S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, key));
InputStream objectData = object.getObjectContent();
// Process the objectData stream.

Leave a Reply

Your email address will not be published. Required fields are marked *