0

I have created a maven project and in that project one properties file. Now to access that properties file I have to put entire path of that file. How can I use slash to access the base directory, so that I just need to write:

properties.load(new FileReader("/testdata.properties"));<br>

instead of

properties.load(new FileReader("C:/Users/windows7/workspace/project/package/testdata.properties"));
paul
  • 4,087
  • 14
  • 62
  • 127

2 Answers2

1

May I suggest taking a look at System Properties home or class path resource instead of using slash?

Atul
  • 2,530
  • 1
  • 29
  • 33
  • It's safe to always use / in paths like that. java handles it just fine. – evanchooly Dec 17 '13 at 14:07
  • Yes, I agree with that. Mainly I meant it as a habit. And as a beginner using slashes can get confusing. – Atul Dec 18 '13 at 05:25
  • @Atul, I went to that link, its good to know but doesnt solve my query.What if I want to load Chrome Binary from my resources directory, there I will provide entire path, but I just want to use slash to reach my home directory (project dir). – paul Dec 18 '13 at 12:27
  • @paul the resources relative to classpath can be loaded and read based on the classpath. You can have a look at Jon's answer here: http://stackoverflow.com/a/1464366/668951 – Atul Dec 19 '13 at 05:32
1

System.getProperty("user.dir") will help you to navigate to the path of your directory. You can append to that path to reach to your file location.

Darshan Mehta
  • 28,982
  • 9
  • 60
  • 90
  • This is not the question, what if I want to load Chrome Binary from my resources directory, there I will provide entire path, but I just want to use slash to reach my home directory (project dir). UpVote for this answer is not right, please downvote as I dont have privileges to do so. – paul Dec 18 '13 at 12:07