Swarnim Prabhat
Swarnim Prabhat

Reputation: 89

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. Example: File file=new File(path); if(!file.exists()){ file.mkdirs(); }

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

Upvotes: 0

Views: 1601

Answers (2)

Charles Anthony
Charles Anthony

Reputation: 3155

If these reports are temporary or transient (e.g. to be streamed), I would suggest simply creating a temporary file (File#createTempFile) : that way you don't have to worry about their location.

Upvotes: 1

Kevin
Kevin

Reputation: 56059

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 + 
                       "myFile";
File file = new File(path);
...

Upvotes: 1

Related Questions