Hi all!!
I need to download file by using JSF(richfaces)command button action
In my action method the code is like
FacesContext context = FacesContext.getCurrentInstance();
PortletResponse response = (PortletResponse)context.getExternalContext().getResponse();
//Reading files
String Files = "D:\\test\\err.txt";
File f = new File(Files);
FileInputStream istr = new FileInputStream(Files);
BufferedInputStream bstr = new BufferedInputStream(istr); // promote
int size = (int) f.length(); // get the file size (in bytes)
byte[] data = new byte; // allocate byte array of right size
bstr.read(data, 0, size); // read into byte array
bstr.close();
HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(response);
ServletOutputStream out = httpServletResponse.getOutputStream();
But when i try to access ServletOutputStream object it throw error like
java.lang.IllegalStateException: Cannot obtain OutputStream because Writer is already in use
Please help
Please sign in to flag this as inappropriate.