Windows环境
String path="d:\\temp";
String regex ="^[a-zA-Z]:(((\\\\(?! )[^/:*?<>\\\"\"|\\\\]+)+\\\\?)|(\\\\)?)\\s*$";
if(path.matches(regex)) {
System.out.println("success");
}else {
System.out.println("file");
}
Linux环境
String path="/usr/local/temp/";
String regex ="^\\/(\\w+\\/?)+$";
if(path.matches(regex) || path.matches(regex1)) {
System.out.println("success");
}else {
System.out.println("file");
}