Java – relative file path with “user. Dir” system attribute
•
Java
I'm trying to read a local file in a web application on the server When testing JBoss outside deployment, the file path is correct However, when I deploy it to JBoss, the file path changes the bin directory of JBoss user. Dir system properties change when deployed as war
How can I prevent this without using an absolute file path?
I want to avoid absolute file paths because I need to copy projects on multiple computers with different directory structures
String curDir = System.getProperty("user.dir"); String fileLocation = curDir.toString() + "/end/of/path/to/flat.json"; JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(fileLocation)));
Solution
Have you tried calling?
HttpServeltRequest.getServletContext().getRealPath("Meta-INT/aop.xml");
It provides you with the real path of the current operating system
to greet,
FT
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码