How to set the permissions to a file in java?



How to set the permissions to a file in java?..

Answer / Abhinav Gupta

To set permissions for a file in Java, you can use the `Files` class from the `java.nio` package along with the `setPosixFilePermissions()` method. You need to create a `Set<PosixFilePermission>` object that contains the desired permissions (such as OWNER_READ, OWNER_WRITE, and OTHERS_EXECUTE) and then call the setPosixFilePermissions() method on your File object.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is the equal sign?

1 Answers  


What are aggregate functions explain with examples?

1 Answers  


Explain the difference between extends thread vs implements runnable in java?

1 Answers  


What is void keyword?

1 Answers  


What is return null in java?

1 Answers  


What is the difference between inner class and nested class?

1 Answers  


How many bits is a word?

1 Answers  


What is math in java?

1 Answers  


What are thread priorities and importance of thread priorities in java?

1 Answers  


How do you override a variable in java?

1 Answers  


What are the methods to rectify ambiguities in the interfaces in JAVA?

1 Answers   CGI,


Difference between overloading and overridding?

4 Answers  


Categories