• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file not writable?

 
Steven Woodford
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steven Woodford
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about sharing options? Could another application have exclusive use of the file?
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic