如果文件存在且不会删除我的旧文件,我想用增量编号对文件名进行版本控制。请帮我。谢谢!
List items = upload.parseRequest(request);
FileItem file = (FileItem)items.get(1);
String fileName = file.getName();
String filePath = uploadPath + File.separator + fileName;
File storeFile = new File(filePath);
if(storeFile.exists()){
**/*Do logic to change the filename of the existed file*/**
}else{
System.out.println(filePath);
file.write(storeFile);
}
@BalusC this what I do sir:
String prefix = FilenameUtils.getBaseName(fileName);
String suffix = FilenameUtils.getExtension(fileName);
File newfileName = File.createTempFile(prefix + "-", "." + suffix, new File(uploadPath));
file.write(newfileName);
我的第一次上传结果为:Programming Language Reflection.docx 但我的第二次上传结果为:Programming Language Reflection15897278330376654158
这是什么原因?