Prev | Current Page 562 | Next

Frank Zammetti

"Practical DWR 2 Projects"


deleteFile() Method
Like creating a file, deleting a file involves nothing but standard Java file I/O code:
public void deleteFile(final String inFullPath) throws Exception {
boolean outcome = false;
try {
outcome = new File(inFullPath).delete();
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Exception occurred: " + e);
}
if (!outcome) {
throw new Exception("File/directory could not be deleted\n\n" +
"Possible permission issue?\n\n" +
"(If it's a directory, it must be empty to be deleted)");
}
} // End deleteFile().
Once again, the ubiquitous File class provides a ready-made delete() method for us to
use. As opposed to createFile(), we get the fully qualified path of the file (or directory) to
delete. Once again, we throw an exception on any problem, and we give a hint about the directory
not being empty, since that is the most likely cause of a failure (the account the app server
is running under not having delete permissions or the directory not being empty are probably
the two most likely causes, so both are mentioned).
renameFile() Method
The renameFile() method is another quick hit:
CHAPTER 6 n REMOTELY MANAGING YOUR FILES: DWR FILE MANAGER 322
public void renameFile(final String inOldFullPath,
final String inNewFullPath) throws Exception {
boolean outcome = false;
try {
outcome = new File(inOldFullPath).


Pages:
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574