Swarnim Prabhat Swarnim Prabhat - 3 years ago 266
Linux Question

common path for making directory in linux and windows

I have created a project in vaadin where the reports will be printed in pdf format. Everything is working as supposed but i got stuck at a point where i don't know whether my application will be deployed in linux environment or windows or Mac. I have to specify a path for making dirctory so that the report will be generated in that directory. I know how to make directory in java but problem is can it be common path for all the O.S.
File file=new File(path);

I want the"path" to be common for all the O.S..
Thanks in advance....

Answer Source

I think the best you're going to get is System.getProperty("user.home");. This will give you the user's home directory, and you can stick it in a subdirectory there:

String path = System.getProperty("user.home") + File.pathSeparator + 
                       "myprogram" +  File.pathSeparator + 
File file = new File(path);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download