Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 外部jar可以访问项目中文件夹中的文件吗_Java_Jar - Fatal编程技术网

Java 外部jar可以访问项目中文件夹中的文件吗

Java 外部jar可以访问项目中文件夹中的文件吗,java,jar,Java,Jar,我正在使用一个外部jar(存储在eclipse项目中的lib文件中),该jar需要访问一个我应该传递路径的文件。到目前为止,只有将文件存储在服务器上完全独立的区域中,我才能使其正常工作 我希望能够在项目中整齐地存储此文件。例如,假设testfile.txt位于projects src/testfolder中。在java中,我尝试这样引用该文件: File file = new File("src/testfolder/testfile.txt").getAbsolutePath(); 但这会在

我正在使用一个外部jar(存储在eclipse项目中的lib文件中),该jar需要访问一个我应该传递路径的文件。到目前为止,只有将文件存储在服务器上完全独立的区域中,我才能使其正常工作

我希望能够在项目中整齐地存储此文件。例如,假设testfile.txt位于projects src/testfolder中。在java中,我尝试这样引用该文件:

File file = new File("src/testfolder/testfile.txt").getAbsolutePath();
但这会在我的电脑上返回一条路径。在本例中,它是:

"/home/me/testfolder/testfile.txt"

我希望应用程序是可移植的,这样我就可以在必要时移动jar文件,而不必担心带来外部文件夹。如何在应用程序中引用此文件并将该url传递给外部jar?

jar是否也包含此文件。如果是,则不应该是问题,因为绝对路径将自动处理。

否…外部jar引用位于服务器上的文件。我负责将文件的路径传递给外部jar,但除非我将文件存储在应用程序jar之外的机器上,否则我很难让它正常工作。