0

Possible Duplicate:
How do i programmatically change file permissions?

I want to set read permission for some directory. Because i want to use list() method from java.io.File, but when i print for example this:

System.out.println(fileDir.list());  

i get "null", according to the documentation it may mean that I do not have permissions to the directory, where the file is located.

Community
  • 1
  • 1
user1825271
  • 69
  • 1
  • 6

1 Answers1

1

You could use JNA to call a native C library (as an alternative to using JNI).

The only problem with JNA is that it has a higher process time than JNA, so it becomes impractical if you try to modify a large number of files/directories.

Edit for code

import com.sun.jna.Library;
import com.sun.jna.Native;

public class ChmodTest {
    private static LinkedOSLibrary linkedLibrary = 
        (LinkedOSLibrary ) Native.loadLibrary("c", LinkedOSLibrary.class);

    public static void main(String[] args) {
        linkedLibrary.chmod("/path/to/file", 0755);
    }
}

interface LinkedOSLibrary extends Library {
    public int chmod(String path, int mode);
}

Source

Timr
  • 1,012
  • 1
  • 14
  • 29