File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java code for giving write permission to group(775) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java code for giving write permission to group(775)" Watch "Java code for giving write permission to group(775)" New topic
Author

Java code for giving write permission to group(775)

sup rty
Greenhorn

Joined: Mar 04, 2010
Posts: 22
Hi,
I dont know if it is the correct place to post my query. If any one has any idea kindly revret asap. My java application creates a folder with 755 permission when file.mkdir() is used. According to the requirement, group needs to have write permission as well i,e it should be 775 for the folder created. Is there any way in java 1.5 or 1.6 to do so i.e to provide write permission to group. If any one has any idea kindly let me know....my email id : [ deleted e-mail address ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19068
    
  40


Java 6 did add the capability to set write permissions, but I don't think you can set it at a group level.... so your best option is probably runtime.exec(chmod).


BTW, this topic is not related to threads. Moving to the general forum.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
sup rty
Greenhorn

Joined: Mar 04, 2010
Posts: 22
Hi Henry, thank you for the reply...i also have been searching for a solution for the bug...found a few.....but as you mentioned about the exec command...if i try out something like this:
Process p = Runtime.getRuntime().exec("chmod 775" ," path of my file");....will it work....thanks in advance
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Please UseTheForumNotEmail.

I deleted your e-mail address from your post. Note that posting your e-mail address in a public forum is not a good idea - did you know that there are hackers on the web that search the Internet for e-mail addresses, and then use those e-mail addresses to send junk e-mail to? That's how they get your address and why you receive junk mail.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
sup rty
Greenhorn

Joined: Mar 04, 2010
Posts: 22
@Jesper...thanks for the info...was new to the forum so didnt know...will keep in mind about not posting my emailid in the forum.
@ henry....i understood the way you mentioned above ....but will p = Runtime.getRuntime().exec("chmod", commands ,f); where chmod is the unix command, commands is an array striing and f is the file ....will it work in window system...as i am passing a unix command...is it possible to execute a unix command in the exec() function in windows OS...Kindly revert asap and also if you know any other way or any other API which can do the task for me...kindly let me know about it...thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Windows has a totally different permission model, so no, chmod will not work.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sup rty
Greenhorn

Joined: Mar 04, 2010
Posts: 22
Hi Rob...thank you for the information , so could you suggest any solution by which it could be done ....that is giving 775 permission to group using java ...thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19068
    
  40

supratimC chakraborty wrote:Hi Rob...thank you for the information , so could you suggest any solution by which it could be done ....that is giving 775 permission to group using java ...thanks



That is the whole point. In Windows, there is no concept of 775. Permissions are given on a user by user basis -- there is no concept of setting up a group (there is, with vista, but there is no concept of the group for the file). How can you do something that just isn't possible?


To further elaborate, with Vista, there is an owner for the file. And this owner can give read and / or write permission on a user by user basis. There is also a concept of groups, which can also be given access on a group by group basis. With this concept, it is possible for users (or users in groups), who are not owners, to have individual (or group) permissions for the file. This is different from unix, where a file belongs to a single user and group, and permissions are given out as such.

I haven't played much with this new feature, so you'll have to try it out, or wait til someone else explains it better to you.

Henry
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

This behaviour is not new to Window Vista. It has been part of Windows 2000 and beyond, although sometimes it was hidden.

Any file or folder has an owner; this can be a user or a group. Users and groups can both be either local or part of domain. Furthermore, additional rights can be set up for each user or group specifically. For instance. user Rob can get read and modify rights whereas group Users gets only read rights. As Henry said, any user or group can get any rights.
sup rty
Greenhorn

Joined: Mar 04, 2010
Posts: 22
thanks rob and henry...seems like my issue might not be solved using normal java coding....just to give a brief description of my application....i have a daemon process which basically takes input from the database and copies files from one location to another and when it does so , there is a folder created using java file.mkdir() function and when it is done it gives 755 permission by default. there is a requirement to make it 775, so that group also could write....according to both of you there mite not be a standard procedure to do so using java...i would probably try finding out some solution...meantime if anyone gets to know about it...kindly reply...thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19068
    
  40

supratimC chakraborty wrote:seems like my issue might not be solved using normal java coding....just to give a brief description of my application....i have a daemon process which basically takes input from the database and copies files from one location to another and when it does so , there is a folder created using java file.mkdir() function and when it is done it gives 755 permission by default. there is a requirement to make it 775, so that group also could write....according to both of you there mite not be a standard procedure to do so using java.


I'm totally missing the point of the problem.... You have a system that creates a file with the wrong permissions in Unix. You want a solution that fixes it, but the solution that we suggested only works in Unix, where is the only place that you have a problem (or could have this problem). Hence, you are rejecting the solution, because the problem doesn't exist in Windows?

Henry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19068
    
  40

supratimC chakraborty wrote: and when it is done it gives 755 permission by default. there is a requirement to make it 775, so that group also could write.


And BTW, you can also easily fix this by setting the umask in your .profile for the user running the program. Or in the script that starts the java program, if you don't want to make it user-wide.

Henry
sup rty
Greenhorn

Joined: Mar 04, 2010
Posts: 22
Hi henry,

so if i add umask 022 for my folder in the /etc/profile....it should created the folder with 775 permissions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java code for giving write permission to group(775)