String fileOne = "C:/1236.pdf";
String fileTwo = "C:/22.pdf";
String mergedFileLocation = "C:/myMergedData.pdf";
after the merging is done
rename an existing file
i need to rename and replacing the mergedFileLocation equals to fileOne
i.e., myMergedData.pdf to 1236.pdf
It is unclear whether you're asking about changing the value of the variable, or about actually renaming the file.
If it's the former, then simply use variable assignment: mergedFileLocation = fileOne
.
If it's the latter, the method you're looking for is File.renameTo
:
if (new File(mergedFileLocation).renameTo(new File(fileOne))) {
// rename successful
} else {
// rename has failed
}
精彩评论