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();
            }

    }

}

RA19
  • 709
  • 7
  • 28

1 Answers1

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();
Peter Bruins
  • 807
  • 9
  • 25
  • The variable was missing a data type. I added string and it ok. How do i append the file + the location for each itteration? – RA19 Apr 25 '17 at 14:13
  • 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? – RA19 Apr 25 '17 at 14:17