File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java code for giving write permission to group(775)

 
sup rty
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
sup rty
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sup rty
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows has a totally different permission model, so no, chmod will not work.
 
sup rty
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic