Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current project path from eclipse using java

Tags:

java

eclipse

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 ...

like image 758
dev777 Avatar asked Dec 01 '25 17:12

dev777


1 Answers

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");
like image 190
Abhijeet Avatar answered Dec 04 '25 05:12

Abhijeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!