68 310
Assignments Done
Successfully Done
In November 2018

Answer to Question #63985 in Java | JSP | JSF for hamod

Question #63985
write a java code segment to rename the file "wet.bin" to "dry.bin" iff the file is found on directory named "d:/avc/win/hadit/",otherwise you should create this file and instruct jvm to delete this new file upon termination
Expert's answer
String filePathSrc ="d:/avc/win/hadit/wet.bin";
String filePathDes ="d:/avc/win/hadit/dry.bin";

File fileSrc = new File(filePathSrc);
File fileDes = new File(filePathDes);

Boolean result;
try {
if (fileSrc.exists()){
result= fileSrc.renameTo(fileDes);
if(result) {
System.out.printf("File \"%s\" was rename to \"%s\"...%n",filePathSrc,filePathDes);
} else {
result = fileSrc.createNewFile();
if(result) {
System.out.printf("File \"%s\" was create...%n",filePathSrc);
System.out.printf("File \"%s\" will be delete on termination...%n",filePathSrc);
} catch (NullPointerException e) {
} catch (IOException e){

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions