[英]Cannot find file in netbeans + glassfish project
這是我的文件夾項目
我想閱讀文件book-form.html,它位於我的項目的目錄網絡中,並將其放入字符串中。
這就是我將函數稱為“ getFileContent”的方式:
String content = getFileContent("web/book-form.html");
這是函數:
public String getFileContent(String filePath){
String line, content = new String();
try {
File file = new File(filePath);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
while((line = br.readLine()) != null){
content += line;
}
br.close();
fr.close();
} catch(IOException e){
System.out.println(e.getMessage());
}
return content;
}
我的問題是netbeans告訴我找不到我的文件book-form.html
有任何想法嗎 ?
另外,如果您使用jdk 7+,則應在最后一個代碼塊中關閉流或使用try-with-resource
我找到了方法:
基本上,該程序位於Glassfish的主文件夾中,因此需要從系統根目錄放置文件的整個路徑,以使該程序可以找到您的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.