62 523
Assignments Done
98,7%
Successfully Done
In June 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);
}
fileSrc.deleteOnExit();
System.out.printf("File \"%s\" will be delete on termination...%n",filePathSrc);
}
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions