如何在Windows中从Java创建非只读目录 [英] How to create non-read-only directories from Java in Windows

查看:198
本文介绍了如何在Windows中从Java创建非只读目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 myFileObject.mkdirs()创建目录。在Windows中,每个创建的目录都标记为只读。虽然我可以(奇怪地)仍然写入目录,但它在删除内容时会造成恶化。

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.

是否有一些系统属性或我可以设置的内容以便新目录的默认权限是读写吗? (我搜索了SO和网络,除了其他人抱怨同样的事情之外没有找到任何东西。)必须为目录树调用setWritable是一件痛苦的事。 (如果它有所不同,我在Windows 7上使用J2SE 1.6.0_23。)

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.)

推荐答案

据我了解有没办法从java做到这一点,这不是java问题。例如,让我们从cmd创建文件夹,您将看到同样的问题( ms错误)。

cmd

md sampleDir

attrib -r sampleDir

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.

如果您可以创建将创建此作业的.bat文件,您可以从Java调用它:

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.

这篇关于如何在Windows中从Java创建非只读目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆