Created
May 22, 2014 09:23
-
-
Save azakordonets/ff758e856d3823d9089b to your computer and use it in GitHub Desktop.
This method allow you to create file in specific folder under your project root. If you want to to save it somewhere on your computer, you can use "user.home" instead of "user.dir"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // get System properties : | |
| Properties properties = System.getProperties(); | |
| // get Operating System home directory | |
| String home = properties.get("user.dir").toString(); | |
| // get Operating System separator | |
| String separator = properties.get("file.separator").toString(); | |
| // your directory name | |
| String directoryName = "directoryName"; | |
| // your file name | |
| String fileName = "filename"; | |
| // create your directory Object (wont harm if it is already there ... | |
| // just an additional object on the heap that will cost you some bytes | |
| File dir = new File(home+separator+directoryName); | |
| // create a new directory, will do nothing if directory exists | |
| dir.mkdir(); | |
| // create your file Object | |
| File output = new File(dir,fileName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment