Java System Property Variables
Often when writing a program a file path is needed where a username variable exists. For example, storing files in the user's Temp directory for temporary files. To achieve this, we can use the following method:
System.getProperty(String key);</code>
The method will return the system property based on the sting key that is passed through with the method. Using the above example, here is how to create a file array of the Temp directory.
File directory = new File("c:\\users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Temp");
File[] files = directory.listFiles();
files </code> will now consist of all the files in the user's Temp directory.
Written by Pete Wicken
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Java
Authors
Related Tags
#java
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#