Java reads system attributes and environment variables, and java environment variables

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.