Java method to get platform specific line separators and Java path separators
- 2020-04-01 02:55:45
- OfStack
[question]
Line separators, path separators, and so on are often different under different systems. Such as
The line separator is in windows Next is rn In the Linux The following is n . in Mac Next is r
The path separator is in windows Next is In the LInux Next is /
How do I get the current platform delimiter in a Java program, and other system-related state?
"Implementation"
import java.util.Properties;
public class SeparatorUtils {
static final Properties PROPERTIES = new Properties(System.getProperties());
public static String getLineSeparator(){
return PROPERTIES.getProperty("line.separator");
}
public static String getPathSeparator(){
return PROPERTIES.getProperty("path.separator");
}
}
class SeparatorUtilTest{
public static void main (String[] args){
System.out.println("Line separator is: " + SeparatorUtils.getLineSeparator());
System.out.println("Path separator is: " + SeparatorUtils.getPathSeparator());
}
}
【 notes 】
Other properties available:
Java version
Java Runtime environment version
Java. Vendor
Java Runtime environment vendor
Java. Vendor. Url
Java Supplier URL
Java. Home
Java The installation directory
Java. Vm. Specification version
Java Virtual machine specification 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 vendor
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 The class path
Java. Library. The path
A list of paths to search when loading the library
Java. IO. Tmpdir
The default temporary file path
Java.com piler
The name of the JIT compiler to use
Java. Ext dirs
Path to one or more extended directories
OS. The name
The name of the operating system
OS. The arch
The architecture of the operating system
OS, version
Version of the operating system
File. The separator
File separator (in UNIX systems, "/")
Path. The separator
Path separator (" : "on UNIX systems)
Line. The separator
Line separator (" /n "on UNIX systems)
The user. The name
The user's account name
The user. The home
The user's home directory
User. Dir
The user's current working directory