开发者

renaming and replacing the contents of a string in java [closed]

开发者 https://www.devze.com 2023-03-18 10:04 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous,开发者_StackOverflow vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current
It's difficult to tell what is being asked here. This question is ambiguous,开发者_StackOverflow vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号