Java中的平台无关路径 [英] Platform independent paths in Java
问题描述
我知道文件的相对路径,并希望能够在Linux和Windows上将其作为文件
对象处理。
I know the relative path of a file, and want to be able to handle it as a File
object on both Linux and Windows.
在Java中指定与平台无关的路径的最佳方法是什么?
What is the best way to specify platform-independent paths in Java?
推荐答案
文件
class包含以下可用于特定于平台的文件路径的公共成员:
The File
class contains the following public members that you can use for platform specific file paths:
static String pathSeparator
:
系统相关的路径分隔符,为方便起见,表示为字符串。
static char pathSeparatorChar
:
系统相关的路径分隔符。
static字符串分隔符
:
系统相关的默认名称分隔符,为方便起见,表示为字符串。
static char separatorChar
:
系统相关的默认名称分隔符。
static String pathSeparator
:
The system-dependent path-separator character, represented as a string for convenience.
static char pathSeparatorChar
:
The system-dependent path-separator character.
static String separator
:
The system-dependent default name-separator character, represented as a string for convenience.static char separatorChar
:
The system-dependent default name-separator character.
这篇关于Java中的平台无关路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!