I am getting the all well known FileNotFoundException when i try to call a .txt file that holds some text. I used various path convinations, but i dont get the right one.
Here is how i call it:
private String generateActivationLinkTemplate() {
String htmlText = "";
try {
Scanner scanner = new Scanner(new FileReader(
"/web/emailActivationTemplate.txt"));
while (scanner.hasNextLine()) {
htmlText += scanner.nextLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return htmlText;
}
The full path to the file looks like this:
C:\jee6workspace\BBS\WebContent\web\emailActivationTemplate.txt
How should i tell my program to find this file in the most flexible way?
One way – access to file through servlet context, f.e. i’m use in my Wicket project
in your case
so you only need to get your servlet context in proper place
Other way – try to access to file through classpath.