Google Groups Home
Help | Sign in
Directory permissions in Java 5
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Veerle  
View profile
 More options Sep 5, 10:00 pm
Newsgroups: comp.lang.java.programmer
From: Veerle <veerleve...@hotmail.com>
Date: Fri, 5 Sep 2008 05:00:49 -0700 (PDT)
Local: Fri, Sep 5 2008 10:00 pm
Subject: Directory permissions in Java 5
Hi,

I am writing unit tests that have to be able to run anywhere.
(developers pc's are Win XP ; the server is Linux). In order to get
the coverage to 100%, I want to test a piece of code where the
creation of a temporary file fails.

What I want to do is create a subfolder in the temporary folder (=
System.getProperty("java.io.tmpdir")) in the setup part of the unit
test. Then I want to change the permissions of the subfolder so that
the creation of a temporary file in it fails by throwing an
IOException or some other Exception. This way I can garantee that the
unit test will work on other developers pcs and on the server as well.
In the tearDown part, I clean up the folder that I've created.

I have to do this in Java 5, but when looking at the File api for java
5, I only see the possibility to set the folder to readonly (method
setReadOnly()). But appearantly, in Win XP, when a folder is readonly,
it is still possible to create a file in it (tried it in the Windows
Explorer and it works there as well). So this doesn't give me my
IOException that I want. So I need to find a way to actually change
the folder permissions so that for the current user the folder is not
accessible. In Java 6, I see in the api that File has a lot more
methods: setReadable, setWriteable which probably would of help, if I
had Java 6.

Is there a way in Java 5 to modify the folder permissions in such a
way that is OS independent?

Veerle


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Claudio Nieder  
View profile
 More options Sep 6, 8:04 am
Newsgroups: comp.lang.java.programmer
From: Claudio Nieder <priv...@claudio.ch>
Date: Sat, 06 Sep 2008 00:04:43 +0200
Local: Sat, Sep 6 2008 8:04 am
Subject: Re: Directory permissions in Java 5
Hi,

> setReadOnly()). But appearantly, in Win XP, when a folder is readonly,
> it is still possible to create a file in it (tried it in the Windows
> Explorer and it works there as well).

If you meant to say that even if you set it to readonly in windows
explorer, then you still can create a file in it, then you can forget it,
because if the OS does not support blocking the file creation then you
will never be able to do it in Java.

If you meant to say that setting readonly through Javas setReadOnly()
does not stop file creation, but Windows itself could do it - e.g. by
changing the directory permission in windows explorer - then you are just
out of luck in doing a portable pure Java solution. You then need to use
OS calls to set the permission either through JNI or using JNA (https://
jna.dev.java.net/).

claudio
--
Claudio Nieder, Talweg 6, CH-8610 Uster, Tel +4179 357 6743,
www.claudio.ch


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google