Java文件分隔符、路径间的分隔符 File separator vs pathSeparator

原文链接 :Java File Separator vs File Path Separator

1. Overview 概述

Different operating systems use different characters as file and path separators. When our application has to run on multiple platforms, we need to handle these correctly.

不同的操作系统使用不同的字符作为文件和路径的分隔符,当我们的程序需要跨平台时,必须要能正确的处理此种状况。

Java helps us to pick an appropriate separator and provides functions to help us create paths that work on the host's operating system.

而Java语言,会根据运行机器操作系统的不同,来帮助我们来选取一种合适的分隔符来使用,并提供多种函数来帮助我们创建使用文件路径。

In this short tutorial, we'll understand how to write code to use the correct file and path separators.

而这一篇就是来介绍如何在编码时使用正确的文件路径分隔符。

2. File Separator 文件路径分隔符

The file separator is the character used to separate the directory names that make up the path to a specific location.

文件分隔符就是一个字符,是用来把组成一个文件路径中各个文件夹分隔区分的特殊标识符。

2.1. Get the File Separator 获取系统的文件路径分隔符

There are several ways to get the file separator in Java.

We can get the separator as a String using File.separator:

在Java语言中有几种方式来获取文件路径分隔符,如,可以使用File.separator来获取String型的分隔符,示例如下:

String fileSep
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值