如何在 Windows 中通过 Java 创建非只读目录
我正在使用 myFileObject.mkdirs()
创建目录。在 Windows 中,创建的每个目录都被标记为只读。尽管我仍然可以(奇怪地)写入该目录,但在删除内容时会造成麻烦。
是否有一些系统属性或我可以设置的东西,以便新目录的默认权限是读写? (我在 SO 和网络上进行了搜索,除了其他人抱怨同样的事情之外,没有找到任何东西。) 必须为目录树调用 setWritable 是一件痛苦的事情。 (如果有影响的话,我在 Windows 7 上使用 J2SE 1.6.0_23。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有办法从 java 做到这一点,这不是 java 问题。例如,让我们从 cmd 创建文件夹,您将看到相同的问题 (毫秒错误)。
命令
md 样本目录
attrib -r exampleDir
属性将保持在创建步骤时的状态。但是,如果您看到“只读”的蓝色方块,则默认情况下它并未标记为只读。蓝色仅代表未确定的空白状态。只有在框中有复选标记时,才会将其标记为只读。
如果您可以创建将创建此作业的 .bat 文件,您可以从 Java 调用它:
这不是真正的方式,但如果它有效 - 那就比什么都好。
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:
It's not true way but if it's work - it's better then anything.