Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access resource file(html, text) outside war

 
swapnil kataria
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to access a file which is on application server, but not the part of war.
I tried it using file handling, it works fine, but don't know how efficient it will be,
can someone have some idea of doing it easily

FileInputStream file = new FileInputStream(filePath);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i = 0;
while ((i = file.read()) != -1) {
byteArrayOutputStream.write(i);
}
response.setContentType("text/html");
response.setHeader("Content-Disposition",
"inline; myfile.html");
response.setContentLength(byteArrayOutputStream.size());
ServletOutputStream outputStream = response.getOutputStream();
byteArrayOutputStream.writeTo(outputStream);
outputStream.flush();
outputStream.close();
byteArrayOutputStream.close();
file.close();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic