How can I create a file with limited privilege in Java?

84 views Asked by At

I want to create a File using Java, that allows the program to modify the contents, however any external user should not be able to go to the path and manually delete or update that file. In other words I want to revoke privilege from users to be able to delete/update that file. For example:

path = "C:\\newfile.txt"
File file = new File(path);
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("hello world");

The above code allows the program to write hello world to the file. I want to make sure that no one can delete the file manually from "C:\". How do I do that?

0

There are 0 answers