Java reads system attributes and environment variables, and java environment variables
Sometimes, when writing an application, you need to write data files and log files to the file system. In this case, you need to determine the operating system type and the current user's home directory to standardize file writing, enables applications to adapt to multiple operating system platforms.
This article uses the built-in JDK class System to obtain the System attribute set.
Import java. util. iterator; import java. util. map; import java. util. properties; public class TestSysprops {public static void main (String [] args) {System. out. println ("print system attributes... "); Properties props = System. getProperties (); for (Iterator <Object> it = props. keySet (). iterator (); it. hasNext ();) {String key = (String) it. next (); String value = (String) props. get (key); System. out. println (key + "\ t" + value);} System. out. println ("Print environment variables... "); Map <String, String> map = System. getenv (); for (Iterator <String> it = map. keySet (). iterator (); it. hasNext ();) {String key = it. next (); String value = map. get (key); System. out. println (key + "\ t" + value );}}}
Using path. sepatator file. sepatator, you can easily classify the operating system types by region.
In dos/windows, the path Delimiter is a semicolon;The file Delimiter is a backslash.\On unix/linux, The Delimiter is a colon.:The file Delimiter is a forward slash./
Therefore, when processing uploaded files,
1. It is recommended to write the file to the directory corresponding to the system property "user. home ".
The reason is that there is no write permission for the write;
2. It is recommended that the application can create a. Hide directory.
Maintain application independence and reduce the impact on other files in the same directory