Folder/File creation in java are dependent on the user from which you're executing the code. My app is creating the user-specific folder/files using Runtime.exec but the thing is now we are going to support multiple OS, accordingly the commands I'm executing are going to change.
Is there any pure java specific solution where folder/files will be created by specific user's ownership?
1 Answer
It's fairly easy, you just need to create the file as normal, then call Files.setOwner(). Alternatively, create a file with Files.createFile(), and then make sure you pass in a file attribute with the expected owner.
Note that in most operating systems, your process will need to run as privileged process to assign files to a different user.
java.nio.file.Files.CreateDirectoryandjava.nio.file.Files.CreateFile?