• Post Reply Bookmark Topic Watch Topic
  • New Topic

Another File Deletion Problem

 
RobT
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've searched the forum(s) and tried some of the examples and I am still having a problem deleting a file. My code looks like this:

String s_SourcePath = "N:\\INPUT_DEV\\";
String s_File = "thisFile";

File filetoBeDeleted = new File(s_SourcePath + s_File);
System.out.println("File Absolute path: " +
filetoBeDeleted.getAbsolutePath());
boolean success = new File(s_SourcePath + s_File).delete();
if (!success) {
// Deletion failed
System.out.println("File: " + filetoBeDeleted + " NOT deleted");
}
else {
System.out.println("File: " + filetoBeDeleted + " deleted");
}

The file is never deleted. If anyone has any suggestions on what might be the cause, I would greatly appreciate it.

RobT
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code works for me.
Probably you don't have permission to delete the file?

A question beside:
Why do you create a new File-handle, to delete the file?
And please use [ code]-tags (-button).
 
RobT
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I was trying the code from an example I found and didn't realize the second 'new' for the file. Thanks for your help. Next time I'll remember to use the code tags.


RobT
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!