本文整理汇总了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();
}
示例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));
}
}
示例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";
}
}
示例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);
}
}
示例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;
}
示例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()};
}
示例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()};
}
示例8: isExecutable
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isExecutable() {
return Files.isExecutable(Paths.get(path));
}