This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes how to access resource file(html, text) outside war Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "how to access resource file(html, text) outside war" Watch "how to access resource file(html, text) outside war" New topic
Author

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

swapnil kataria
Ranch Hand

Joined: Feb 26, 2011
Posts: 64
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();
 
jQuery in Action, 2nd edition
 
subject: how to access resource file(html, text) outside war