2

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

micstr
  • 5,080
  • 8
  • 48
  • 76
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • 1
    Java creates directories/files with the default permissions specified by the OS. If the permissions are not correct I suggest you change it at the OS level. – Peter Lawrey Nov 07 '11 at 18:50
  • @Peter, I don't think he's talking about permissions but about the read-only attribute. – Harry Johnston Nov 07 '11 at 19:33
  • @Ted, I can't reproduce this. Can you provide more information, maybe some simple code exhibiting the problem? Have you tried the latest update, 6u29? – Harry Johnston Nov 07 '11 at 19:45
  • @Ted, regarding Psycho's answer, are you sure the directories are really being set read-only? Have you checked using the attrib command? – Harry Johnston Nov 07 '11 at 20:33
  • @HarryJohnston, I thought the read-only attribute had something to do with the permissions of the directory. – Peter Lawrey Nov 07 '11 at 21:37
  • 1
    @Peter, no, the read-only attribute predates file permissions. It's not often used nowadays. – Harry Johnston Nov 08 '11 at 02:58

1 Answers1

2

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.

Psycho
  • 335
  • 2
  • 7
  • The article you link to describes a limitation in the GUI, it doesn't describe an error and certainly doesn't explain why Ted's directories are getting marked read-only (or having odd permissions assigned to them as the case may be). – Harry Johnston Nov 07 '11 at 20:27
  • Oh, I think I see - are you saying that Ted may be mistakenly thinking the directories are read-only because the GUI is misleading? – Harry Johnston Nov 07 '11 at 20:31
  • Yep, as I understand, this attribute(default attribute for created files) doesn't says that this folder is read only. But some limitations are could be (required google :) ) but it's not question for java. – Psycho Nov 07 '11 at 20:43
  • Windows Explorer shows a green square. I didn't realize that was an "undetermined blank state". The reason I looked at it in the first place was that when I tried to delete the directory tree that my program created, a pop-up claimed that I needed administrator privilege. Seeing the green square, I thought that was the problem. But I haven't been able to reproduce the privilege problem since then. So I think this is the right answer--I was misinterpreting what I was seeing. Thanks to everyone for the quick feedback. – Ted Hopp Nov 07 '11 at 22:52