2

I have tried using below ways and both are giving error as "java.io.FileNotFoundException"

JSONArray a = (JSONArray) parser.parse(new FileReader(bucket+"/"+key));

and

JSONArray a = (JSONArray) parser.parse(new FileReader(http://S3URL...);
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134

2 Answers2

0

You cannot read a file from S3 directly. There are multiple ways of doing this:

  1. Use the HTTP interface provided by Amazon Web Services. You may refer to this documentation http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html

  2. Use the Amazon AWS SDK http://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk

Once you have read the file then you can pass the IO Stream to create your JSON Object.

This is as good as downloading the file from your bucket first and then creating a JSON Object from the read content

piy26
  • 1,574
  • 11
  • 21
0

This worked for me

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getObjectContent())); String line; String iString = "";

while((line = reader.readLine()) != null) { iString = iString + line; }

JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(iString);