1
由Maven組裝後,將war-file放在外部Tomcat服務器上。當servlet啓動時,有一個FileNotFoundException
,它找不到2.html
文件(路徑相對於 - "2.html"
)。該文件位於應用程序的根目錄中。當我使用內置的Eclipse內部服務器Tomacat(Ran as - 在服務器上運行)啓動項目時 - 一切正常,文件已找到(路徑絕對是 - "F: /javaEEBelhard/Task-4/WebContent/WEB-INF/1.html"
)。Servlet/Tomcat文件路徑
這裏是Eclipse代碼:
try
{
FileInputStream fileIntputStream = new FileInputStream("2.html");
InputStreamReader inputStreamReader = new InputStreamReader(fileIntputStream, CHARSET_NAME);
BufferedReader reader = new BufferedReader(inputStreamReader);
String line;
while ((line = reader.readLine()) != null)
{
writer.println(line);
}
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
你是不是缺少一個左括號'{''後try'? – Smittey
它不會編譯.. –