How to create non-read-only directories from Java in Windows

半世苍凉 提交于 2019-12-01 09:48:48

问题


I'm creating directories using myFileObject.mkdirs(). In Windows, every directory that gets created is marked as read-only. Although I can (oddly) still write to the directory, it creates aggravation when it comes to deleting things.

Is there some system property or something I can set so that the default permission on new directories is read-write? (I've searched on SO and the web and haven't found anything besides other people complaining about the same thing.) It's a pain to have to call setWritable for a directory tree. (If it makes a difference, I'm using J2SE 1.6.0_23 on Windows 7.)


回答1:


As I understand there is no way to do this from java it's not java problem. For example let's create folder from cmd and you will see the same problem (ms error).
cmd
md sampleDir
attrib -r sampleDir

Attribute will stay as it was on creation step. But If you are seeing a blue square for "Read only", then it is not marked as read-only by default. The blue just stands for a undetermined blank state. Only if it had a check mark in the box would it be marked as read-only.

If you can create .bat file that will create this job you could call it from Java:

Runtime.getRuntime().exec("cmd /c run.bat");

It's not true way but if it's work - it's better then anything.



来源:https://stackoverflow.com/questions/8041049/how-to-create-non-read-only-directories-from-java-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!