且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Windows和Linux上从Java读取文件

更新时间:2023-12-03 23:23:22

如果您知道当前的工作目录(请使用以下命令进行测试:

If you know the current working directory (test it with:

System.out.println(new File(".").getAbsolutePath());

您可以对../../XML/RequestXML之类的相对目录进行硬编码

you can hardcode a relative directory like ../../XML/RequestXML

记录:尽管这可能有所帮助,但我仍然相信您应该尝试使用配置参数或通过将其作为类路径中可用的资源加载来解决此问题.

For the record: although this may help, I still believe you should try to solve this with a configuration parameter or by loading it as a resource available in the classpath.