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 |