Reputation: 1019
I have a project named SampleProj in eclipse.
The project structure is mentioned as below :
SampleProj
|
-- META-INF
|
-- dbdetails.properties
Currently,I'm reading the file like this :
FileReader reader = new FileReader("C://Workspace//SampleProj/META-INF//dbdetails.properties");
But this path is local to my system rit. So, I want to make this path generic.
So, I'm trying to keep the path like this :
FileReader reader = new FileReader("SampleProj/META-INF//dbdetails.properties");
But,I'm getting file not found exception.
How can I read this file from Project. Can anyone please help me out regarding this ...
Upvotes: 3
Views: 13335
Reputation: 11
IF your using spring web-mvc project use this samplecode:
String path=session.getServletContext().getRealPath("/ui_resources/images/logo.png");
Upvotes: 0
Reputation: 44965
Then SampleProj/META-INF/dbdetails.properties
should work as path since a relative path is relative to the user working directory corresponding to the System property user.dir
.
Upvotes: 1
Reputation: 4309
You can retrieve using :
String workingDir = System.getProperty("user.dir");
Then you can do it like this :
FileReader reader = new FileReader(workingDir +"//SampleProj//META-INF//dbdetails.properties");
Upvotes: 4
Reputation: 3507
As fas as your development is concerned you can do it like below but once you deploy the project its better to add file in classpath
String currentDirectory=System.getProperty("user.dir");
FileReader reader = new FileReader(currentDirectory+"/SampleProj/META-INF//dbdetails.properties");
Upvotes: 0