Java to get platform-dependent row and Java path delimiters _java

Source: Internet
Author: User

Problem

The line separator, the path separator, and so on, are often different under different system platforms. Such as

Copy Code code as follows:

Row delimiters under Windows are \ r \ n, under Linux \ n, under Mac \ r
The path separator is \ Under Windows, under Linux is/

How do I get the separator for the current platform in the Java program, and other system-related states?

Achieve

Copy Code code as follows:

Import java.util.Properties;

Public class Separatorutils {

   /* System Properties to get separators */
  & nbsp Static Final Properties Properties = new properties (System.getproperties ());

   /**
     * Get line separator on current platform
      * @return Line separator
     */
    public static String Getlineseparator () {
        return properties.getproperty ("Line.separator") );
   }

   /**
     * Get path separator on current platform
      * @return Path separator
     */
    public static String Getpathseparator () {
        return properties.getproperty ("Path.separator") );
   }
}

Class separatorutiltest{
public static void Main (string[] args) {
System.out.println ("line separator are:" + separatorutils.getlineseparator ());
System.out.println ("Path separator is:" + separatorutils.getpathseparator ());
}
}

Note

Other properties that can be obtained:

Java.version

Java Runtime Environment version

Java.vendor

Java Runtime Environment Vendor

Java.vendor.url

URLs for Java vendors

Java.home

Java installation directory

Java.vm.specification.version

Java Virtual Machine spec version

Java.vm.specification.vendor

Java virtual Machine specification Vendor

Java.vm.specification.name

Java Virtual Machine Specification name

Java.vm.version

Java Virtual Machine implementation version

Java.vm.vendor

Java virtual Machine implementation provider

Java.vm.name

Java virtual Machine implementation name

Java.specification.version

Java Runtime Environment specification version

Java.specification.vendor

Java Runtime Environment specification Vendor

Java.specification.name

Java Runtime Environment Specification name

Java.class.version

Java Class format version number

Java.class.path

Java class Path

Java.library.path

List of paths to search when loading libraries

Java.io.tmpdir

Default temporary file path

Java.compiler

The name of the JIT compiler to use

Java.ext.dirs

Path to one or more extended directories

Os.name

The name of the operating system

Os.arch

The architecture of the operating system

Os.version

Version of the operating system

File.separator

File delimiter (in UNIX system is "/")

Path.separator

Path separator (in UNIX system is ":")

Line.separator

Row delimiter (in UNIX system is "n")

User.Name

User's account name

User.home

User's home directory

User.dir

User's current working directory

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.