I have a HttpServletResponse object and need to write a file contained in the jar. The following code segments do not work for me.
URI uri = <myclass>.class.getResource("/" + filename).toURI();
PrintWriter out = response.getWriter();
File f = new File(uri);
FileReader bis = new FileReader(f);
char[] buff = new char[1024];
int bytesRead;
// Simple read/write loop.
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
out.write(buff, 0, bytesRead);
}
I know that this will work
InputStream inputStream = <myclass>.class.getResourceAsStream("/" + filename);
but I cannot get the PrintWriter out.write to write the inputStream.
Can anyone tell me how this can be done.
Thanks
Resolved using the following