Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public boolean createFolder(String path) {
    try {
        // create meta-data for your folder and set content-length to 0
        ObjectMetadata metadata = new ObjectMetadata();
        // create empty content
        InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
        // create a PutObjectRequest passing the folder name suffixed by /
        PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucketName, path + SUFFIX, emptyContent,
        // send request to S3 to create folder
        boolean doesObjectExist = this.s3client.doesObjectExist(bucketName, path);
        if (!doesObjectExist) {
        return true;
    } catch (Exception e) {
        return false;

What I have tried:

code refactoring in the aws s3 client to refactor the code for to reduce the complexity
Updated 23-May-19 7:34am
Richard MacCutchan 23-May-19 9:51am    
What is the problem?
OriginalGriff 23-May-19 10:13am    
Commented student style, swallowed exceptions, copied from internet and doesn't want tutor to know, ... :laugh:
Member 14364887 23-May-19 13:05pm    
i want decrease the code in short form how do i that???
Richard MacCutchan 24-May-19 3:29am    
Start by analysing what the code is doing, and remove any redundant elements of it. At a quick glance there is nothing that stands out, apart from the fact that there is a missing return statement at the end.
Member 14364887 23-May-19 13:06pm    
i want the code in short form how i do that??

1 solution

public boolean createFolder(String path) {
    return true;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900