开发者

Change Sticky bit with Java

Is there any way to add/remove the sticky bit (S_ISVTX) on a file and 开发者_C百科a directory with Java ?


Call out to the /bin/chmod command. Since this sticky bit is platform specific Java will not provide a standard library API for it.


According to this post it's is not possible directly but however you can workaround if you have sufficient permissions to delete. In a gist, you 'll have to read the file, delete it and write it back with modifications.


I've already has the same problem. At first, I use Runtime to exe chmod command, it works but I don't know why after some days, my program usually die without any reason. My program is simple, so I think there's something like memory,resource leak when use Runtime.exec in java. Later, I switch to use JNA to direct call to libc function, it works well till now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜