2017-02-16 45 views
0

我有一个应用程序部署在正在尝试读取其他目录中的文件的tomcat上。读取应用程序外部的文件

应用程序路径(WAR文件) -/tomcat的/ Web应用程序/应用

文件是目录 - /home/anotherapplication/file.txt

我写了一个程序(servlet的)在我的应用程序中读取目录结构上的文件。我试过下面的选项来阅读它,但每个给我的文件没有发现异常。

File inputFile = new File("/home/anotherapplication/file.txt"); - 从根目录

File inputFile = new File("../../home/anotherapplication/file.txt");路径 - 从应用程序的相对路径

任何想法如何做到这一点?

谢谢。

+0

您的应用程序是否具有适当的权限来读取该文件? – pablochan

+0

您必须将路径映射到类似c:\ abc \ def \ file.txt的文件 –

+0

@pablochan - yes tomcat用户有权读取该文件 – Vivek

回答

-1

你试过了吗?

File inputFile = new File("../../../home/anotherapplication/file.txt"); 
-- relative path from application