amazon-web-servicesamazon-s3inputstreamfileinputstream

How do I convert an InputStream to S3ObjectInputStream in Java?


I want to convert a FileInputStream to a S3ObjectInputStream.

This is my current code:

InputStream is = new FileInputStream(file);
S3ObjectInputStream sObject = (S3ObjectInputStream)is;

However, it's giving the error:

java.io.FileInputStream cannot be cast to com.amazonaws.services.s3.model.S3ObjectInputStream

Solution

  • You need cast as a InputStream

    InputStream is = new FileInputStream(file);
    S3ObjectInputStream sObject = (InputStream) is;
    

    Hope it helps