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.
Asked
Active
Viewed 96 times
-1
-
1Does this answer your question? [Reading a plain text file in Java](https://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java) – WoAiNii Oct 04 '20 at 16:53
-
@WoAiNii, no, you don't want to save it to a file first – Jasper de Vries Oct 07 '20 at 06:08
1 Answers
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
- 19,370
- 6
- 64
- 102