gpt4 book ai didi

java - 连接字符串中的绝对文件路径

转载 作者:行者123 更新时间:2023-12-02 07:09:31 24 4
gpt4 key购买 nike

我需要在一个字符串中连接几个绝对文件路径。但如果我使用字符,它可能是文件名或路径的一部分,字符串将会困惑。可以使用哪种分隔符?

现在我使用 File.pathSeparator,对于 Windows 7,它是“;”。但这个字符可以是文件名的一部分。

SO question

Semicolons are legal in NTFS file paths.

最佳答案

您可以使用File.pathSeparator :

The system-dependent path-separator character, represented as a string for convenience. This string contains a single character, namely pathSeparatorChar:

The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.

关于java - 连接字符串中的绝对文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15700633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com