Java中的平台无关路径 [英] Platform independent paths in Java

查看:124
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆