Is possible in Java to manage creating files / directories (if program runs as ROOT) with different user/group ?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can achieve this in JDK 7 using new IO API (Java NIO)
There are getOwner()/setOwner() methods available to manage ownership of files, and to manage groups you can use PosixFileAttributeView.setGroup()
The following code snippet shows how to set the file owner by using the setOwner method:
There is no special-purpose method in the Files class for setting a group owner. However, a safe way to do so directly is through the POSIX file attribute view, as follows:
You can achieve JDK 7 (Java NIO)
Use setOwner() method....
Usage Example: Suppose we want to make "joe" the owner of a file:
Get more information about same from below url
http://docs.oracle.com/javase/tutorial/essential/io/file.html
Example : Set Owner
Example : GetOwner