-1

I uploaded a file and i can get the file name, type, size and content. The content is in a format of byte array. I want the cotnet in it's original format, which is text file(String). Is there a way to read the uploadedFile of the primefaces like the File in io. or is there a way i can read the content in a string format.

1 Answers1

1

It's simple. The uploaded file will contain a byte[] of the contents of the uploaded file, so you can simply construct a String from it:

public void handleUpload(final FileUploadEvent event) throws IOException {
  String content = new String(event.getFile().getContent(), StandardCharsets.UTF_8);
}

See also:

Jasper de Vries
  • 13,693
  • 6
  • 54
  • 86