public static void main(String[] args)
    throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
    try {
      /* play.min.io for test and development. */
      MinioClient minioClient = new MinioClient("https://play.min.io:9000", "Q3AM3UQ867SPQQA43P2F",
                                                "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

      /* Amazon S3: */
      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
      //                                           "YOUR-SECRETACCESSKEY");

      StringBuilder builder = new StringBuilder();
      builder.append("{\n");
      builder.append("    \"Statement\": [\n");
      builder.append("        {\n");
      builder.append("            \"Action\": [\n");
      builder.append("                \"s3:GetBucketLocation\",\n");
      builder.append("                \"s3:ListBucket\"\n");
      builder.append("            ],\n");
      builder.append("            \"Effect\": \"Allow\",\n");
      builder.append("            \"Principal\": \"*\",\n");
      builder.append("            \"Resource\": \"arn:aws:s3:::my-bucketname\"\n");
      builder.append("        },\n");
      builder.append("        {\n");
      builder.append("            \"Action\": \"s3:GetObject\",\n");
      builder.append("            \"Effect\": \"Allow\",\n");
      builder.append("            \"Principal\": \"*\",\n");
      builder.append("            \"Resource\": \"arn:aws:s3:::my-bucketname/myobject*\"\n");
      builder.append("        }\n");
      builder.append("    ],\n");
      builder.append("    \"Version\": \"2012-10-17\"\n");
      builder.append("}\n");
      minioClient.setBucketPolicy("my-bucketname", builder.toString());
    } catch (MinioException e) {
      System.out.println("Error occurred: " + e);
    }
  }
public static void main ( String [ ] args ) throws IOException , NoSuchAlgorithmException , InvalidKeyException , XmlPullParserException { try { MinioClient minioClient = new MinioClient ( "https://play.min.io:9000" , "Q3AM3UQ867SPQQA43P2F" , "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" ) ; StringBuilder builder = new StringBuilder ( ) ; builder . append ( "{\n" ) ; builder . append ( "    \"Statement\": [\n" ) ; builder . append ( "        {\n" ) ; builder . append ( "            \"Action\": [\n" ) ; builder . append ( "                \"s3:GetBucketLocation\",\n" ) ; builder . append ( "                \"s3:ListBucket\"\n" ) ; builder . append ( "            ],\n" ) ; builder . append ( "            \"Effect\": \"Allow\",\n" ) ; builder . append ( "            \"Principal\": \"*\",\n" ) ; builder . append ( "            \"Resource\": \"arn:aws:s3:::my-bucketname\"\n" ) ; builder . append ( "        },\n" ) ; builder . append ( "        {\n" ) ; builder . append ( "            \"Action\": \"s3:GetObject\",\n" ) ; builder . append ( "            \"Effect\": \"Allow\",\n" ) ; builder . append ( "            \"Principal\": \"*\",\n" ) ; builder . append ( "            \"Resource\": \"arn:aws:s3:::my-bucketname/myobject*\"\n" ) ; builder . append ( "        }\n" ) ; builder . append ( "    ],\n" ) ; builder . append ( "    \"Version\": \"2012-10-17\"\n" ) ; builder . append ( "}\n" ) ; minioClient . setBucketPolicy ( "my-bucketname" , builder . toString ( ) ) ; } catch ( MinioException e ) { System . out . println ( "Error occurred: " + e ) ; } }
MinioClient.setBucketPolicy() example.