Getting System Properties during Java application

Source: Internet
Author: User
Tags file separator

The Java language is favored by many programmers because of its object-oriented, cross-platform, portability and high security, and more and more people use it as the first choice of application software development language.

When a Java application is running, especially when running across a platform, you need to determine the operating system type, user JDK version, and user working directory that changes with the work platform to ensure that the program runs correctly. In general, you can use the methods in the System attribute class (properties) provided by JDK to quickly get information about your work environment.

In addition, the program developer can define the system properties files related to the application and dynamically load the programmer-defined property files to control the operation during the execution of the user program.

Through the analysis of the System attribute class, this paper introduces how to define the System Properties file and discusses the definition of the security policy file.

When the application starts executing, the program first reads the system's default properties. If a user property file is defined, the application loads the property file. The program can dynamically modify the property definition according to the execution, and save the property file before the program finishes running.

Gets the method of the property:

Contains (object value), ContainsKey (object key): If a given argument or property keyword is defined in the property sheet, the method returns True, otherwise false;

GetProperty (String key), GetProperty (string key, string default): Gets the key value based on the given property keyword;

List (PrintStream s), List (printwriter W): Output The contents of the property sheet in the output stream;

Size (): Returns the number of property keywords defined in the current property sheet.

To set the method for a property:

Put (object key, Object value): Appends the property key and keyword value to the property sheet;

Remove (Object key): Removes the keyword from the property sheet.

Get System Properties

System Properties refer to the operating system configuration information and software information associated with the user program. The property keywords that are typically associated with user programs include:

File.separator: File separator, Windows environment "\", UNIX environment is "/";

User.home: Directory of Household heads;

Java.home:Java the installation directory of real-time operating environment;

installation directory of Java.ext.dirs:JDK;

Os.name: Operating system name;

User.Name: User login name;

Os.version: Operating system version;

Path.separator: The current operating system's path separator;

User.dir: The directory where the current user program resides.

Related Article

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.