java - AWS S3 fetchObjects throwing error when does not exists -


i fetching objects s3 , method throws exception, when given folder not exists. how should write code provides objectlisting blank or null when folder not present.

objectlisting objectlisting = s3client.listobjects(bucketname, foldername); 

can check see if exists catching exception:

public boolean exists(amazons3 s3client, string bucketname, string foldername) {   try {     s3client.getobjectmetadata(bucketname, foldername);     return true;   } catch (exception e) {     // log exception   }   return false; } 

set objectlisting null if not exist

if (!exists(s3client, bucketname, foldername)) {    objectlisting = null; } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -