Reputation: 5713
I have couple of questions here.
I am using the following to write a stream to a file. I want to write to outside the webapp container, as on a redeploy all the files will be deleted.
InputStream in = event.getFile().getInputstream();
OutputStream out = new FileOutputStream(path + fName);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
I do not know if we can achieve this by externalContext of facesContext. If so, please give me an example of how to do it.
How can I access this ? example, if i have to use it as follows, what path do i have to use?
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("mypictures/john.jpg");
Thanks in advance !
Upvotes: 1
Views: 1126
Reputation: 115378
You are doing everything right. Use (for example) user tmp directory to write this file (System.getProperty("user.tmp.dir")
). To access this file use FileInputStream
in exactly the same manner as you are using FileOutputStream
.
Upvotes: 3