1

How to configure properties file in Eclipse java?

How can we provide relative addresses in the properties file?

These two lines are working

modelsPath=C:\\Users\\rishika.shrivastava\\workspace\\CSVWEB\\src\\com\\models

csvFilePath=c:/users/rishika.shrivastava/workspace/CSVWEB/

But when i use relative addresses like this:

modelsPath=/CSVWEB\\src\\com\\models

csvFilePath=/CSVWEB/

it doesn't work.

Kalle
  • 2,282
  • 1
  • 24
  • 30
Shivanshu Goyal
  • 500
  • 9
  • 25
  • what exactly is not working? – Fran Montero Jul 08 '15 at 10:31
  • For the relative paths you are assuming the current directory is the workspace directory - which is probably not the case. – greg-449 Jul 08 '15 at 10:44
  • I have exactly the same problem, in JBOSS, I have to reference a JKS file inside a properties file that are in the class path. When I use the absolute path, it works otherwise it doesn't ! (Same behavior in WIN and in LINUX) – Tom Feb 09 '17 at 16:08

1 Answers1

0

If your files are to be resource on the classpath, then you should read them as resources, not as files on the file system, (which is what happens when you use File or a FileXxx variant).

To read resources from the classpath, you could do

getClass().getResource("/com/models/file")

Or if you need an InputStream you can do

getClass().getResourceAsStream("/com/models/file")

Some Resources

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720