Skip to content

Instantly share code, notes, and snippets.

@pbandreddy
Created March 29, 2023 12:45
Show Gist options
  • Save pbandreddy/d7267c4839141c6e616e367695f329a5 to your computer and use it in GitHub Desktop.
Save pbandreddy/d7267c4839141c6e616e367695f329a5 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
// Set the directory path where the file is located
String directoryPath = "C:/pt-scripts/Scripts/MicroServices/FileService/";
// Set the original file name
String originalFileName = "image.jpeg";
// Set the new file name
String newFileName = Instant.now().toEpochMilli() + ".jpeg";
// Create a File object for the original file
File originalFile = new File(directoryPath + originalFileName);
// Create a File object for the new file
File newFile = new File(directoryPath + newFileName);
// Rename the file
//originalFile.renameTo(newFile);
// Copy the original file to the new file
Files.copy(originalFile.toPath(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
// Store the new file name in a variable
vars.put("newFileName", newFileName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment