0

Im trying to use a string builder to append both the first file with its location then new line second file with its location etc. How do I do this? Whats the correct syntax? Whats wrong with my below loop?

@Override
public List<FileUpload> uploadFile(MultipartFile[] files, String windowsUsername, String number) {
List<FileUpload> uploadList = new ArrayList<FileUpload>();
        for (MultipartFile file : files) {

                FileUpload result = itsmFileService.uploadAttachment(file, number);


                uploadList.add(result);     



        }
        String supportCallID;
        supportCallID = this.getSupportCallIDForTicketNumber(number);

int i = 0;
            for (FileUpload loopLocation : uploadList){
                notesSection = uploadList.get(i).getLocation();
                StringBuilder sb = new StringBuilder();
                sb.append(notesSection);
                sb.toString();
            }

    }

}

4
  • 2
    Where is your StringBuilder? Commented Apr 25, 2017 at 14:08
  • Updated question Commented Apr 25, 2017 at 14:09
  • Put StringBuilder sb = new StringBuilder(); before the for loop . Commented Apr 25, 2017 at 14:10
  • get the error notesSection cant be resolved to a variable Commented Apr 25, 2017 at 14:10

1 Answer 1

1

You are creating a new StringBuilder everytime the loop is run. Try the following:

StringBuilder sb = new StringBuilder();

for (FileUpload loopLocation : uploadList){
     string notesSection = uploadList.get(i).getLocation();

     sb.append(notesSection);
}

sb.toString();
Sign up to request clarification or add additional context in comments.

2 Comments

The variable was missing a data type. I added string and it ok. How do i append the file + the location for each itteration?
My filename is in my array uploadList, and my location in notesSection for each itteration, how do i append it together then output it outside the loop?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.