Answer to Question #63985 in Java | JSP | JSF for hamod
2016-12-08T08:43:45-05:00
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
1
2016-12-13T11:10:08-0500
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 !
Learn more about our help with Assignments:
Java JSP JSF
Comments
Leave a comment