Java File Mod Change chmod(File file, int mode)

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

Description

chmod

License

Open Source License

Declaration

public static int chmod(File file, int mode) 

Method Source Code

//package com.java2s;
/**/*from  w ww . j  a  v  a  2 s . c o m*/
 *     Copyright (C) 2013-2014  the original author or authors.
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License,
 *     any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

import java.io.File;

import java.lang.reflect.Method;

public class Main {
    public static int chmod(File file, int mode) {
        return chmod(file.getName(), mode);
    }

    public static int chmod(String filename, int mode) {
        try {
            Class<?> fspClass = Class.forName("java.util.prefs.FileSystemPreferences");
            Method chmodMethod = fspClass.getDeclaredMethod("chmod", String.class, Integer.TYPE);
            chmodMethod.setAccessible(true);

            return (Integer) chmodMethod.invoke(null, filename, mode);
        } catch (Throwable ex) {
            return -1;
        }
    }
}

Related

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