Reputation: 115
I am having a file and i need to read it using FileInputStream in java. I need to give the path which should be readable in all OS. Now i have given
(new FileInputStream("..\\config.properties"));
which is a windows readable format But this is a non readable in Unix.
Is there any way common for all OS.
Upvotes: 1
Views: 148
Reputation: 949
You have two options:
For standalone classes you can use:
new FileInputStream("../config.properties")
For classes in JAR file you can use:
InputStream input = getClass().getResourceAsStream("../config.properties");
This should help.
Upvotes: 4
Reputation: 201527
Yes. Instead of
new FileInputStream("..\\config.properties")
This should work everywhere
new FileInputStream("../config.properties")
Or you could use
new FileInputStream(".." + java.io.File.separator + "config.properties")
Upvotes: 2