开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜