/**
* 新旧附件字符串拼接(去重已存在的附件)
* @param oldFile 旧附件字符串 如:1001|aaa.jpg,1003|ccc.jpg
* @param newFile 新附件字符串 如: 1002|bbb.jpg,1003|ccc.jpg
* @return string 拼接后的结果 1003|ccc.jpg,1001|aaa.jpg,1002|bbb.jpg
*/
public static String fileJoint(String oldFile,String newFile){
String tempFile=oldFile+","+newFile;
String[] strArrFile=tempFile.split(",");
HashMap<String, String> fileMap=new HashMap<String, String>();
for(String strFile:strArrFile){
String[] ss = strFile.split("\\|");
fileMap.put(ss[0], strFile);
}
StringBuffer buffer=new StringBuffer();
for(String value:fileMap.values()) {
buffer.append(","+value);
}
return buffer.toString().substring(1, buffer.toString().length());
}
/**
* 新旧附件字符串清除(清除掉不需要的附件)
* @param oldFile 旧附件字符串 如:1001|aaa.jpg,1003|ccc.jpg
* @param newFile 新附件字符串 如: 1002|bbb.jpg,1003|ccc.jpg
* @return string 清除后的结果 1001|aaa.jpg
*/
public static String fileClear(String oldFile,String newFile){
String[] arrOFile = oldFile.split(",");
HashMap<String, String> fileMap=new HashMap<String, String>();
for(String strFile:arrOFile){
String[] ss = strFile.split("\\|");
fileMap.put(ss[0], strFile);
}
String[] arrNFile = newFile.split(",");
Iterator<Map.Entry<String, String>> iterator = fileMap.entrySet().iterator();
while (iterator.hasNext()) {
String value = iterator.next().getValue();
for(String strFile:arrNFile){
if(StringUtil.isNotBlank(value) && (value).equals(strFile)){//如果值相等,清除
iterator.remove();
}
}
}
StringBuffer buffer=new StringBuffer("");
for(String value:fileMap.values()) {
buffer.append(","+value);
}
if(buffer.toString().length()>0){
return buffer.toString().substring(1, buffer.toString().length());
}else{
return "";
}
}
附件字符串拼接,及去重工具类
最新推荐文章于 2025-07-27 09:29:51 发布
154

被折叠的 条评论
为什么被折叠?



