88
99package example ;
1010
11- import java .io .IOException ;
1211import java .util .ArrayList ;
1312import software .amazon .awssdk .core .exception .SdkException ;
1413import software .amazon .awssdk .awscore .exception .AwsServiceException ;
1918import software .amazon .awssdk .services .s3 .model .ObjectIdentifier ;
2019import software .amazon .awssdk .services .s3 .model .DeleteObjectsRequest ;
2120
21+
2222public class S3DeleteObject {
2323 private static final Region REGION = Region .of ("eu-west-1" ); // Region name
2424
25- public static void main (String [] args ) throws IOException {
25+ public static void main (String [] args ) {
2626
2727 if (args .length < 2 ) {
28- System .out .println ("Not enough parameters.\n Proper Usage is: java -jar s3deleteobject.jar <BUCKET_NAME> <OBJECT_NAME>" );
28+ System .out .println ("Not enough parameters.\n " +
29+ "Proper Usage is: java -jar s3deleteobject.jar " +
30+ "<BUCKET_NAME> <OBJECT_NAME>" );
2931 System .exit (1 );
3032 }
3133
@@ -45,6 +47,7 @@ public static void main(String[] args) throws IOException {
4547
4648 try {
4749 System .out .println ("Deleting object ..." );
50+
4851 ArrayList <ObjectIdentifier > toDelete = new ArrayList <ObjectIdentifier >();
4952 toDelete .add (ObjectIdentifier .builder ().key (keyName ).build ());
5053
@@ -54,7 +57,9 @@ public static void main(String[] args) throws IOException {
5457 .delete (Delete .builder ().objects (toDelete ).build ())
5558 .build ();
5659 s3client .deleteObjects (delReq );
60+
5761 System .out .println ("Deleted" );
62+
5863 } catch (S3Exception e ) {
5964 if (e .statusCode () == 404 ) {
6065 System .out .println ("Error: Bucket does not exist!!" );
0 commit comments