Skip to content

Instantly share code, notes, and snippets.

@CedricL46
Created January 11, 2019 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricL46/e5c4ad8805e5e2f8217e14e1b80b9639 to your computer and use it in GitHub Desktop.
Save CedricL46/e5c4ad8805e5e2f8217e14e1b80b9639 to your computer and use it in GitHub Desktop.
Read full tutorial on how to convert org.apache.myfaces.trinidad.model to java.io.File here :
public static File uploadedFileToFileConverter(UploadedFile uf) {
InputStream inputStream = null;
OutputStream outputStream = null;
//Add you expected file encoding here:
System.setProperty("file.encoding", "UTF-8");
File newFile = new File(uf.getFilename());
try {
inputStream = uf.getInputStream();
outputStream = new FileOutputStream(newFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (IOException e) {
//Do something with the Exception (logging, etc.)
}
return newFile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment