戦争アーカイブからテキストファイルを読み取り、実行時にフェイスレットページにコンテンツを表示しようとしています。私のフォルダ構造は次のとおりです
+戦争アーカイブ>+リソース>+メール>+file.txt
次のコードを使用して、resources / email/file.txtフォルダー内のファイルを読み取ろうとします
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
ただし、問題は、上記のコードを使用したメソッドを実行すると、AFileNotFoundException
がスローされることです。次のコード行を使用してファイルを取得しようとしましたが、成功しませんでした
File file = new File(FacesContext.getCurrentInstance()
.getExternalContext().getRequestContextPath() + "/resources/email/file.txt");
私はまだ取得しFileNotFoundException
ます。これはどのように発生し、どうすれば解決できますか?