I want to be able to have my paths work on any server not just my dev box.
Right now I declear the full path of the file name as such on my local drive.
filename = "H:\test\SourceCode\sample\src\file.txt"
try
{
BufferedReader in = new BufferedReader(new FileReader(fileName));
line = in.readLine();
in.close();
}
catch (IOException e) {
log.error("Exception Message", e);
}
How can I set the file path so when I create the .war file I can use it on any server. Such as filename = “src/file.txt” (This doesn’t work for me)
Two usual ways:
getClass().getResourceAsStream("/..")– resolves the path relative to the classpath – that is,WEB-INF/classes(and jar files)getServletContext().getResourceAsStream("/..")resolves the path relative to the webapp root. That is –webapps/applicationname