I am trying to read a text file from my military archive and display the contents on the facelets page at runtime. My folder structure is as follows
+ war archive> + resources> + email> + file.txt
I am trying to read the file in the resources / email / file.txt folder using the following code
File file = new File("/resources/email/file.txt"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } StringBuffer buffer = new StringBuffer(); if (reader != null) { String line = reader.readLine(); while (line != null) { buffer.append(line); line = reader.readLine(); // other lines of code
However, the problem is that when I run the method with the above code, A FileNotFoundException . I also tried using the following line of code to get the file, but was not successful
File file = new File(FacesContext.getCurrentInstance() .getExternalContext().getRequestContextPath() + "/resources/email/file.txt");
I am still getting a FileNotFoundException . How is this caused and how can I solve it?
source share