下面列出了java.io.File#canExecute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static private String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
abis = getSupportedAbisLollipop();
else
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
for (String abi: abis) {
File mvpnout = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
if ((mvpnout.exists() && mvpnout.canExecute()) || writeMiniVPNBinary(context, abi, mvpnout)) {
return mvpnout.getPath();
}
}
return null;
}
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) abis = getSupportedABIsLollipop();
else
//noinspection deprecation
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
abis = new String[]{nativeAPI};
}
for (String abi : abis) {
File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
return null;
}
public static DebuggerInfo getDefaultDebugger() {
URL netcoredbgUrl = FileLocator.find(AcutePlugin.getDefault().getBundle(), new Path("netcoredbg")); //$NON-NLS-1$
if (netcoredbgUrl != null) {
try {
netcoredbgUrl = FileLocator.toFileURL(netcoredbgUrl);
File dbgDir = new File(netcoredbgUrl.toURI().normalize()).getAbsoluteFile();
if (!dbgDir.canExecute() && dbgDir.canExecute()) {
Files.setPosixFilePermissions(dbgDir.toPath(), Collections.singleton(PosixFilePermission.OWNER_EXECUTE));
}
return new DebuggerInfo(new File(dbgDir,Platform.OS_WIN32.equals(Platform.getOS()) ? "netcoredbg.exe" : "netcoredbg"), Collections.singletonList("--interpreter=vscode")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} catch (IOException | URISyntaxException ex) {
AcutePlugin.logError(ex);
}
}
return new DebuggerInfo(new File("/home/mistria/apps/netcoredbg-linux-master/netcoredbg/netcoredbg"), Collections.singletonList("--interpreter=vscode")); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Check whether an executable exists, either at a specific path (if a full path is given) or
* on the PATH.
*
* @param executable the name of an executable on the PATH or a complete path to an executable that may/may not exist
* @return whether the executable exists and is executable
*/
public static boolean executableExists(String executable) {
// First check if we've been given the full path already
File directFile = new File(executable);
if (directFile.exists() && directFile.canExecute()) {
return true;
}
for (String pathString : getSystemPath()) {
Path path = Paths.get(pathString);
if (Files.exists(path.resolve(executable)) && Files.isExecutable(path.resolve(executable))) {
return true;
}
}
return false;
}
/**
* Prompts the user for the location of the IDA executable.
*
* @param parent Parent component used to display dialogs.
* @param initialDirectory The directory to select by default.
*
* @return The selected IDA executable or null if no executable was selected.
*/
public static String selectIDADirectory(final Component parent, final String initialDirectory) {
Preconditions.checkNotNull(parent, "IE02067: Parent argument can not be null");
Preconditions.checkNotNull(initialDirectory, "IE02259: Initial directory can not be null");
final CIdaSelectionDialog dialog =
CIdaSelectionDialog.show(SwingUtilities.getWindowAncestor(parent), initialDirectory);
final File selectedFile = dialog.getSelectedFile();
if (selectedFile == null) {
return null;
} else if (!selectedFile.exists()) {
CMessageBox.showError(parent, "File does not exist.");
return null;
} else if (selectedFile.canExecute()) {
return selectedFile.getAbsolutePath();
} else {
CMessageBox.showError(parent, "File is not an executable file.");
return null;
}
}
public Object getValueAt(int row, int column) {
File file = files[row];
switch (column) {
case 0:
return fileSystemView.getSystemIcon(file);
case 1:
return fileSystemView.getSystemDisplayName(file);
case 2:
return file.getPath();
case 3:
return file.length();
case 4:
return file.lastModified();
case 5:
return file.canRead();
case 6:
return file.canWrite();
case 7:
return file.canExecute();
default:
System.err.println("Logic Error");
}
return "";
}
public static String getBasicPermission(File file) {
String per = "";
per += file.isDirectory() ? "d" : "-";
per += file.canRead() ? "r" : "-";
per += file.canWrite() ? "w" : "-";
per += file.canExecute() ? "x" : "-";
return per;
}
@Nullable
public File findExecutable(final String executable, final List<File> locations) {
final List<String> executables = executablesFromName(executable);
for (final File location : locations) {
for (final String possibleExecutable : executables) {
final File foundFile = fileFinder.findFile(location, possibleExecutable);
if (foundFile != null && foundFile.exists() && foundFile.canExecute()) {
return foundFile;
}
}
}
return null;
}
private boolean isInstalled() {
final File kuduMasterBinary = new File(kuduLocalDir, KUDU_MASTER);
final File kuduTabletBinary = new File(kuduLocalDir, KUDU_TABLET);
final boolean okMaster = kuduMasterBinary.exists() && kuduMasterBinary.canExecute();
final boolean okTablet = kuduTabletBinary.exists() && kuduTabletBinary.canExecute();
return okMaster && okTablet;
}
final String findElfReader() {
String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"};
final String cmd = isSolaris ? "elfdump" : "readelf";
for (String x : paths) {
File p = new File(x);
File e = new File(p, cmd);
if (e.canExecute()) {
return e.getAbsolutePath();
}
}
System.err.println("Warning: no suitable elf reader!");
return null;
}
public boolean isSuitable(String guessLocation) {
if (guessLocation == null) {
return false;
}
File f = new File(guessLocation);
return f.isFile() && f.canRead() && f.canExecute();
}
public void chooseADBPath(@NotNull VirtualFile vFile) {
final File adbFile = findADB(vFile);
if (adbFile == null || !adbFile.canExecute() || !adbFile.getName().equalsIgnoreCase("adb")) {
fail2FindADB();
} else {
checkAdbAvailable(adbFile);
}
}
static void setRecursiveExecutable(File path) {
for (File f : path.listFiles()) {
if (f.isDirectory()) {
f.setExecutable(true);
setRecursiveExecutable(f);
} else if (!f.canExecute() && (f.getName().endsWith(".so") || f.getName().endsWith(".dll"))) {
f.setExecutable(true);
}
}
}
private void setReadWrite(File file) {
StringBuilder builder = new StringBuilder();
if (file.canRead()) {
builder.append("可读");
}
if (file.canWrite()) {
if (builder.length() > 0) {
builder.append("/可写");
} else {
builder.append("可写");
}
}
if (file.canExecute()) {
if (file.isFile()) {
if (builder.length() > 0) {
builder.append("/可执行");
} else {
builder.append("可执行");
}
} else if (file.isDirectory()) {
if (builder.length() > 0) {
builder.append("/可进入");
} else {
builder.append("可进入");
}
}
}
if (builder.length() == 0) {
builder.append("无权限");
}
mTvAudioInfoReadWrite.setText(builder.toString());
}
public void setExecutingProgram(File executablePath) {
if (!executablePath.canExecute()) {
LOGGER.warning("File is not executable: " + executablePath.getAbsolutePath());
return;
}
this.executingProgram = executablePath;
}
/**
* Constructs path to Java VM executable and verifies if it exists.
* <p/>
* @param server Payara server entity object.
* @param command lassFish server administration command with local Java VM.
* @return Path to Java VM executable
*/
private static String getJavaVM(final PayaraServer server,
final CommandJava command) {
final String METHOD = "getJavaVM";
String javaVmExe = JavaUtils.javaVmExecutableFullPath(command.javaHome);
File javaVmFile = new File(javaVmExe);
// Java VM executable should exist and should be executable.
if (!javaVmFile.canExecute()) {
LOGGER.log(Level.INFO, METHOD, "noJavaVMExe", javaVmExe);
return null;
}
return javaVmExe;
}
/**
* Checks and creates the directory described by the abstract directory path. This function checks
* if the directory exists and creates it if necessary. It also checks read permissions and
* write permission, if necessary.
*
* @param dir
* The String describing the directory path.
* @param needWritePermission
* A flag indicating whether to check write access.
* @throws IOException
* Thrown, if the directory could not be created, or if one of the checks failed.
*/
private final void checkAndCreateDirectories(File f, boolean needWritePermission) throws IOException {
String dir = f.getAbsolutePath();
// check if it exists and it is not a directory
if (f.exists() && !f.isDirectory()) {
throw new IOException("A none directory file with the same name as the configured directory '" + dir
+ "' already exists.");
}
// try to create the directory
if (!f.exists()) {
if (!f.mkdirs()) {
throw new IOException("Could not create the directory '" + dir + "'.");
}
}
// check the read and execute permission
if (!(f.canRead() && f.canExecute())) {
throw new IOException("The directory '" + dir + "' cannot be read and listed.");
}
// check the write permission
if (needWritePermission && !f.canWrite()) {
throw new IOException("No write access could be obtained on directory '" + dir + "'.");
}
}
private boolean verifyDir(File dir) {
return dir.exists() && dir.canExecute() && dir.isDirectory();
}
public boolean canExecute(File file) {
return file.canExecute();
}
private static boolean isValidGaugeExec(File file) {
return file.exists() && file.isFile() && file.canExecute();
}