title: How to add incremental number to the filename if the file exists?
body: <p>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! </p>
  
  <pre><code>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);
  </code></pre>
  
  <p>My first upload is ok with result of: <strong>Programming Language Reflection.docx</strong>
  But my second upload resulted to: <strong>Programming Language Reflection15897278330376654158</strong></p>
  
  <p>What is the cause of this?</p>