简体   繁体   English

如何以编程方式区分Unix和Windows目录

[英]how programmatically distinguish between Unix and Windows directory

In a java method i am loading a path name into a string variable, not knowing whether it is a Unix or a Windows path name. 在Java方法中,我将路径名加载到字符串变量中,而不知道它是Unix还是Windows路径名。

How can i programmatically check whether it is a Unix or a Windows path? 我如何以编程方式检查它是Unix还是Windows路径?

   if path.contains(":") execute a Windows-related function
   else execute a Unix-related function

won't work, because Unix path names can contain a ":" as far as i know. 据我所知,它将无法工作,因为Unix路径名可以包含“:”。 Same with "/" for Unix , because Windows path names can contain a "/" . 对于Unix,与“ /”相同,因为Windows路径名可以包含“ /”。 So how could i do this best? 那我该怎么做呢?

EDIT: I am loading directory names for remote machines, so i doubt i can use Use System.getProperty("os.name"). 编辑:我正在加载远程计算机的目录名称,所以我怀疑我可以使用Use System.getProperty(“ os.name”)。

i was thinking about using Regex, but since i have no idea about regex in Java i have not considered that yet. 我当时正在考虑使用正则表达式,但是由于我对Java中的正则表达式一无所知,所以我还没有考虑过。

IMHO, using path names to determine OS platform is not the best idea. 恕我直言,使用路径名确定OS平台不是最好的主意。

Use System.getProperty("os.name") 使用System.getProperty(“ os.name”)

and have a look here: How do I programmatically determine operating system in Java? 看看这里: 如何以编程方式确定Java的操作系统?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM