Here you can find the source of chmod(File file, int mode)
public static int chmod(File file, int mode)
//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; } } }