File Write Protected | sorry if this is the wrong forum
I am writing an address book and when you change the name of a contact, the old file needs to be deleted. I am writing this using eclipse running on an Ubuntu 6.06LTS box. When I try to delete the file using .delete(), it is unable to. Using .canWrite() returns the file as being write protected. I used the chmod command to set the permissions to 777 ( read/write/execute for owner/group/everyone ) but it still sees it as protected. I have double, triple, and quadruple checked that I close all streams that could possibly be accessing the file.
What should I do?
# 3
The only thing that accesses it would be a check to see if that file exists...
boolean fileExists = (new File("contacts/" + first + ' ' + last + ".con")).exists();
if (fileExists) {
//Do nothing, just overwrite file...
} else { //file alwasy write protected?!
//Delete original contact file, then write new file
boolean write = (new File(addressBookPanel.contactList.getSelectedValue().toString() + ".con")).canWrite();
if (!write) {
System.err.println("File \"" + addressBookPanel.contactList.getSelectedValue().toString() + ".con\" write protected.");
}
boolean deleted = (new File(addressBookPanel.contactList.getSelectedValue().toString() + ".con")).delete();
if (!deleted) {
System.err.println("Deletion of contact file \"" + addressBookPanel.contactList.getSelectedValue().toString() + ".con\" failed.");
}
}
Message was edited by:
mazikowski
# 5
No, what it does is it checks if the file first + " " + last + ".con" exists. If it does, meaning that the name for that contact hasn't been altered, it just saves over that file. If the file doesn't exist, meaning the name has been altered, it deletes the old file(currently selected name in the JList) and creates a new one using the new name.
# 8
How did I not think of that!?!?
Well, that's my problem, it is unable to find the file... according to my test output:
The name of the file it should delete, based on the .toString() output from a JList (the same method used to open the file, which works fine)
I find it strange that it can find the file and open it, yet .exists() returns false. Any ideas on what could possibly cause something like this?
Thanks for the help!
James Mazikowski