Java File Mod Change chmod(final int mode, final File path)

Here you can find the source of chmod(final int mode, final File path)

Description

chmod

License

Apache License

Declaration

public static void chmod(final int mode, final File path) 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.io.File;

import java.nio.file.Path;

public class Main {
    public static void chmod(final int mode, final Path path) {
        // TODO(dborowitz): Is there a portable way to do this with NIO?
        chmod(mode, path.toFile());//  ww  w . ja  v a 2s.  c  om
    }

    public static void chmod(final int mode, final File path) {
        path.setReadable(false, false /* all */);
        path.setWritable(false, false /* all */);
        path.setExecutable(false, false /* all */);

        path.setReadable((mode & 0400) == 0400, true /* owner only */);
        path.setWritable((mode & 0200) == 0200, true /* owner only */);
        if (path.isDirectory() || (mode & 0100) == 0100) {
            path.setExecutable(true, true /* owner only */);
        }

        if ((mode & 0044) == 0044) {
            path.setReadable(true, false /* all */);
        }
        if ((mode & 0011) == 0011) {
            path.setExecutable(true, false /* all */);
        }
    }
}

Related

  1. chmod(@Nonnull File file, int mode)
  2. Chmod(boolean recursive, String permission, String directoryFile)
  3. chmod(File file, int mode)
  4. chmod(File file, String mode)
  5. chmod(final String path, final String mode)
  6. chmod(String filename, String perm)
  7. chmodX(String filename)