當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。