我在 tomcat 上部署了一个应用程序,它试图读取其他目录中的文件。
应用程序路径(WAR 文件) -/tomcat/webapp/application
文件在目录中 -/home/anotherapplication/file.txt
我在我的应用程序中编写了一个程序(servlet)来读取上述目录结构中的文件。我尝试了以下选项来阅读它,但每个选项都给我找不到文件异常。
File inputFile = new File("/home/anotherapplication/file.txt");
-- 来自根目录的路径
File inputFile = new File("../../home/anotherapplication/file.txt");
-- 来自应用程序的相对路径
知道怎么做吗?
谢谢。
最佳答案
你试过吗?
File inputFile = new File("../../../home/anotherapplication/file.txt");
-- relative path from application
关于java - 读取应用程序之外的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42279889/