1 private void createPath(String path){ 2 String os = System.getProperty("os.name"); 3 String tmpPath = path; 4 //兼容 linux 系统 5 if(os.toLowerCase().startsWith("win")){ 6 tmpPath = path.replaceAll("/", "\\\\"); 7 } 8 //判断路径是否存在 9 File filePath = new File(tmpPath); 10 if(!filePath.exists()){ 11 //不存在,创建目录 12 filePath.mkdirs(); 13 } 14 }