更新时间:2023-12-04 15:51:28
首先,您要指定绝对路径(您的路径以/
开头)
First of all you are specifying an absolute path (your path starts with /
)
第二个FileReader不是在Web应用程序中加载资源的正确方法,如果不提取应用程序之争怎么办?它仍然会失败.
Second FileReader is not the correct way of loading a resource in a web application, what is if your application war is not extracted? It will still fail.
您应使用 ServletContext#getResourceAsStream 以获得 InputStream 并使用它来读取您的资源.
You should use ServletContext#getResourceAsStream to get an InputStream and use it to read your resource.