关于JSP文件上传重命名的问题
对于上传的文件重命名问题,我想上传之后能够根据之前上传的文件名字,如果有的话给其在基础上加1,求大神指教
JSP Java 文件 重命名 上传
public class FileRename {
public String getNewFileName(String originalFileName) {
StringBuffer newFileName = new StringBuffer();
if (null != originalFileName && !"".equals(originalFileName)) {
int port = originalFileName.lastIndexOf(".");
String type = "";
String fileName = "";
if (port != -1) {
type = originalFileName.substring(port + 1);
fileName = originalFileName.substring(0, port);
} else {
fileName = originalFileName;
}
JsonDateValueProcessor jdvp = new JsonDateValueProcessor();
JsonConfig jc = new JsonConfig();
StringBuffer suffix = new StringBuffer("_");
suffix.append(jdvp.processArrayValue(new Date(), jc));
suffix.append("_");
suffix.append(new Random().nextInt(100));
newFileName.append(fileName);
newFileName.append(suffix);
newFileName.append(".");
newFileName.append(type);
}
return newFileName.toString();
}
}