Created
March 29, 2023 12:45
-
-
Save pbandreddy/d7267c4839141c6e616e367695f329a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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