I am working in windows environment. I have a folder on which i have set read only permissions. However, when I try to set read only permissions I'm given two options as to make only the particular folder as read only or make all the files and folders in the selected folder also as read only. I select the first option and make only the selected folder as read only. The above explained actions are done in windows directly. Now i write a java program to read that creates a File class using the above mentioned folder(permissions set to read only). However when I use the method canWrite(), the method returns true. Can you explain why?
My purpose is, the user specifies a file/folder location. If it is a file I have to get the parent folder, check the permissions and delete only if the folder has write permissions and Give a warning if the containing folder is read only. But while testing i found the problem explained in the first paragraph. Please suggest an alternative if possible..
Nirmal Kumar<br />If you have to aim, aim for the moon. Even if you miss you will land among the stars
Hi Nirmal, You can make use of the APIs in File class to accomplish what you need. Just go through the APIs : getParent(),isDirectory(),canWrite() methods. All you have to do is make use of these methods and build your logic.
Give it a try. Go through the javaDoc. It is very important. It is your guide to Java!
I think the above answer is not answering the original poster's question.
I think the answer to the original question is that Java is telling the truth. Try this experiment: -
Create a new folder using Windows Explorer
Set the new folder to Read-Only, using File Properties
Navigate to the new folder and create a new file in it
Sane people would expect that it would not be possible to create a new file in a read-only directory. But on Windows, it is possible - the read-only status of a directory seems to be ignored. Therefore, Java will tell you that you canWrite() a read-only directory, for the simple reason that you can!
<TROLL feed="no">Mr Jobs will sell you a better computer, whenever you're ready...</TROLL>
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
please buy my thing and then I'll have more money:
global solutions you can do in your home or backyard