当前位置: 首页>>代码示例>>Java>>正文


Java Files.isExecutable方法代码示例

本文整理汇总了Java中java.nio.file.Files.isExecutable方法的典型用法代码示例。如果您正苦于以下问题:Java Files.isExecutable方法的具体用法?Java Files.isExecutable怎么用?Java Files.isExecutable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.isExecutable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPermissions

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Returns formatted permissions for current file.
 * @param path Current file.
 * @return Formatted permissions.
 */
private String getPermissions(Path path) {
	char directory = '-';
	if (Files.isDirectory(path))
		directory = 'd';

	char readable = '-';
	if (Files.isReadable(path))
		readable = 'r';

	char writeable = '-';
	if (Files.isWritable(path))
		writeable = 'w';

	char executable = '-';
	if (Files.isExecutable(path))
		executable = 'x';

	return new StringBuilder().append(directory).append(readable)
			.append(writeable).append(executable).toString();
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:26,代码来源:LsShellCommand.java

示例2: checkWritePath

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Check if the provided path is a directory and is readable/writable/executable
 *
 * If the path doesn't exist, attempt to create a directory
 *
 * @param path the path to check
 * @throws IOException if the directory cannot be created or is not accessible
 */
public static void checkWritePath(String path) throws IOException {
  java.nio.file.Path npath = new File(path).toPath();

  // Attempt to create the directory if it doesn't exist
  if (Files.notExists(npath, LinkOption.NOFOLLOW_LINKS)) {
    Files.createDirectories(npath);
    return;
  }

  if (!Files.isDirectory(npath)) {
    throw new IOException(format("path %s is not a directory.", npath));
  }

  if (!Files.isReadable(npath)) {
    throw new IOException(format("path %s is not readable.", npath));
  }

  if (!Files.isWritable(npath)) {
    throw new IOException(format("path %s is not writable.", npath));
  }

  if (!Files.isExecutable(npath)) {
    throw new IOException(format("path %s is not executable.", npath));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:34,代码来源:PathUtils.java

示例3: getVScmdPath

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * 
 * @return the String that should lead to a vsDevCMD which is required to
 *         run cbmc on windows
 * @throws IOException in case the VScmd couldn't be found this gets thrown
 */
public static String getVScmdPath() throws IOException {

    File file = new File(SuperFolderFinder.getSuperFolder() + RELATIVEPATHTOVSCMD);

    if (Files.isExecutable(file.toPath())) {
        return file.getPath();
    } else { // we were unable to locate the command promp in the resources
        // and search now for it in the common install directories

        Path x86 = new File("C:/Program Files (x86)").toPath();
        Path x64 = new File("C:/Program Files").toPath();
        String searchTerm = "Microsoft Visual Studio";
        String pathToBatch = "/Common7/Tools/VsDevCmd.bat";

        ArrayList<String> toSearch = new ArrayList<>();
        Files.list(x86).filter(Files::isReadable).filter(path -> path.toString().contains(searchTerm))
                .forEach(VSPath -> toSearch.add(VSPath.toString()));
        Files.list(x64).filter(Files::isReadable).filter(path -> path.toString().contains(searchTerm))
                .forEach(VSPath -> toSearch.add(VSPath.toString()));

        for (Iterator<String> iterator = toSearch.iterator(); iterator.hasNext();) {
            String toCheck = ((String) iterator.next()) + pathToBatch;

            if (Files.isReadable(new File(toCheck).toPath())) {
                return toCheck;
            }
        }

        ErrorForUserDisplayer.displayError("The progam was unable to find a Developer Command Prompt for Visual Studio. \n"
                + " Please install it if you haven't and search for the vsCMD.bat in it! \n"
                + " Please copy the .bat to the folder /windows/ in your BEST install directory"
                + "(named \"VsDevCmd.bat\") so it can be found automatically.");

        return "The progam was unable to find a Developer Command Prompt for Visual Studio. Look at the error log";
    }
}
 
开发者ID:Skypr,项目名称:BEAST,代码行数:43,代码来源:WindowsOStoolbox.java

示例4: Solution

import java.nio.file.Files; //导入方法依赖的package包/类
public Solution(String pathToFile) {

        try {
            Path filePath = Paths.get(pathToFile);
            fileData = new ConcreteFileData(Files.isHidden(filePath), Files.isExecutable(filePath),
                    Files.isDirectory(filePath), Files.isWritable(filePath));

        } catch (Exception e) {
            fileData = new NullFileData (e);
        }
    }
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:12,代码来源:Solution.java

示例5: convert

import java.nio.file.Files; //导入方法依赖的package包/类
protected PathAttributes convert(final java.nio.file.Path file) throws IOException {
    final boolean isPosix = session.isPosixFilesystem();
    final PathAttributes attributes = new PathAttributes();
    final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class;
    final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS);
    if(Files.isRegularFile(file)) {
        attributes.setSize(a.size());
    }
    attributes.setModificationDate(a.lastModifiedTime().toMillis());
    attributes.setCreationDate(a.creationTime().toMillis());
    attributes.setAccessedDate(a.lastAccessTime().toMillis());
    if(isPosix) {
        attributes.setOwner(((PosixFileAttributes) a).owner().getName());
        attributes.setGroup(((PosixFileAttributes) a).group().getName());
        attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions())));
    }
    else {
        Permission.Action actions = Permission.Action.none;
        if(Files.isReadable(file)) {
            actions = actions.or(Permission.Action.read);
        }
        if(Files.isWritable(file)) {
            actions = actions.or(Permission.Action.write);
        }
        if(Files.isExecutable(file)) {
            actions = actions.or(Permission.Action.execute);
        }
        attributes.setPermission(new Permission(
            actions, Permission.Action.none, Permission.Action.none
        ));
    }
    return attributes;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:34,代码来源:LocalAttributesFinderFeature.java

示例6: getLauncher

import java.nio.file.Files; //导入方法依赖的package包/类
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING,
               StandardCopyOption.COPY_ATTRIBUTES);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:CustomLauncherTest.java

示例7: getLauncher

import java.nio.file.Files; //导入方法依赖的package包/类
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:CustomLauncherTest.java

示例8: isExecutable

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isExecutable() {
    return Files.isExecutable(Paths.get(path));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:5,代码来源:LocalAttributes.java


注:本文中的java.nio.file.Files.isExecutable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。