Search code examples
javafilewindows-7java-7folder-permissions

How to make a folder non-readable in Java?


I am trying to create a folder structure as Test1/gotcha/Test3 I want to make Test1 non-reable. The below code does not work:

new File("D:\\Test1\\gotcha\\Test3").mkdirs();
PrintWriter writer= new PrintWriter("D:\\Test1\\gotcha\\Test3\\testing.txt");
writer.write("Hello");
writer.close();

File f1= new File("D:\\Test1");
f1.setReadable(false,false);
f1.setExecutable(false,false);

I am still able to open the Test1 folder. Any suggestions on how I can fix this?


Solution

  • It is not possible to make folders non-readable in Windows, that is why setReadable() in windows does not work.