How do I programmatically change file permissions?

前端 未结 12 1157
深忆病人
深忆病人 2020-11-22 04:55

In Java, I\'m dynamically creating a set of files and I\'d like to change the file permissions on these files on a linux/unix file system. I\'d like to be able to execute t

12条回答
  •  时光取名叫无心
    2020-11-22 05:49

    Apache ant chmod (not very elegant, adding it for completeness) credit shared with @msorsky

        Chmod chmod = new Chmod();
        chmod.setProject(new Project());
        FileSet mySet = new FileSet();
        mySet.setDir(new File("/my/path"));
        mySet.setIncludes("**");
        chmod.addFileset(mySet);
        chmod.setPerm("+w");
        chmod.setType(new FileDirBoth());
        chmod.execute();
    

提交回复
热议问题