I want to version the file name with incremental number if the file exists which doesn't delete my old file. Please help me. Thanks!
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);
My first upload is ok with result of: Programming Language Reflection.docx But my second upload resulted to: Programming Language Reflection15897278330376654158
What is the cause of this?