1:获取项目路径
public static String resourcePath = ResourceFactory.getInstance().getFilePath() + File.separator;
2:处理斜杠,将 \替换成系统中对应的 斜杠
public static String getPicPath(String path){
if(StringUtils.isBlank(path)){
return "";
}
String temp = path.replaceAll("/", Matcher.quoteReplacement("\\"));
String[] split = temp.split("\\\\");
List<String> list = new ArrayList<>();
for (String s : split) {
if(StringUtils.isNotBlank(s)){
list.add(s);
}
}
if(list.size()==0){
return path;
}
String fileName = list.get(list.size()-1);
if(fileName.indexOf(".")==-1){
return path;
}
String p = "";
for (int i = 0; i < list.size(); i++) {
if(i==0){
p = list.get(i);
}else{
p = p + "/" + list.get(i);
}
}
return p;
}