File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
swapnil kataria
Ranch Hand
Posts: 64
  • 0
  • 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();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic