aspose file tools*
The moose likes Beginning Java and the fly likes file not writable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "file not writable?" Watch "file not writable?" New topic
Author

file not writable?

Steven Woodford
Greenhorn

Joined: Nov 11, 2002
Posts: 12
Hi all, not sure if this is the right place to post but it seems like a simple enough question!
Apart from the file being read-only - what reasons are there for the canWrite() method of the File class to return false?
Thanks in advance
Ste
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Steven,
Welcome to JavaRanch. According to the API docs:
Returns true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.
So, canWrite() will return false if the file does not exist and if the file exists and is read-only.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Steven Woodford
Greenhorn

Joined: Nov 11, 2002
Posts: 12
Thanks Michael, that's what I thought.
I am getting this result when checking a file that I know exists and that I know is not read-only. I will have to look elsewhere for the problem!
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
I am getting this result when checking a file that I know exists and that I know is not read-only
What OS are you using? Could be that whatever context your application is running under doesn't have write permission. This is especially true on all Unix (including Linux) flavors.
Steven Woodford
Greenhorn

Joined: Nov 11, 2002
Posts: 12
Originally posted by Michael Morris:
[b]What OS are you using?

The PC is a Windows NT 4.0 workstation. I am now double-checking user permissions etc.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
sorry to interrupt Michael
hi Steven
Related file object that can not write to a file
(file in Unix term) which is a directory
humm....
you can use the JFileChooser to do that it can avoid the file which does not exist and the file which is directory
the coding is following

If you are not clear what the code do,please post a reply again


Francis Siu
SCJP, MCDBA
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
sorry to interrupt Michael
Actually siu, I'm quite glad to hear from you. I've been worried about you with the SARS problem in Hong Kong. Hope you stay healthy, so I can rib you with Chicken Feet jokes.
Steven Woodford
Greenhorn

Joined: Nov 11, 2002
Posts: 12
Siu,
Thanks for the tip, that looks like a very useful piece of code to make a note of. Don't think it will help me out with this problem though... thanks anyway
Ste
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
How about sharing options? Could another application have exclusive use of the file?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Michael
Actually siu, I'm quite glad to hear from you. I've been worried about you with the SARS problem in Hong Kong. Hope you stay healthy, so I can rib you with Chicken Feet jokes.

Yes...
I am healthy but busy.
If I donate some money to JavaRanch,I am virtually from status "ranch hand"--> Chicken
So, I write all about Chicken Feet that can make
funny marks
thanks for your concerning
Steven Woodford
Greenhorn

Joined: Nov 11, 2002
Posts: 12
Thanks everyone for your suggestions,
In the end, I have had to rename the offending folder, create a new one and copy the original files into the new folder. My program now has full access to the files in the folder.
It looks like this was more of a file system issue than a java issue but I would still be interested to know why this folder suddenly started behaving strangely (I still had full read/write rights to all file from within windows explorer).
Ste
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file not writable?