本文整理汇总了Java中java.nio.file.attribute.BasicFileAttributes.isSymbolicLink方法的典型用法代码示例。如果您正苦于以下问题:Java BasicFileAttributes.isSymbolicLink方法的具体用法?Java BasicFileAttributes.isSymbolicLink怎么用?Java BasicFileAttributes.isSymbolicLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.attribute.BasicFileAttributes
的用法示例。
在下文中一共展示了BasicFileAttributes.isSymbolicLink方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sizeIfKnown
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
@Override
public Optional<Long> sizeIfKnown() {
BasicFileAttributes attrs;
try {
attrs = readAttributes();
} catch (IOException e) {
// Failed to get attributes; we don't know the size.
return Optional.absent();
}
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory() || attrs.isSymbolicLink()) {
return Optional.absent();
}
return Optional.of(attrs.size());
}
示例2: getTypes
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
@Override
public final BitField<Type> getTypes() {
try {
final BasicFileAttributes attr = readBasicFileAttributes();
if (attr.isRegularFile()) return FILE_TYPE;
else if (attr.isDirectory()) return DIRECTORY_TYPE;
else if (attr.isSymbolicLink()) return SYMLINK_TYPE;
else if (attr.isOther()) return SPECIAL_TYPE;
} catch (IOException ignore) {
// This doesn't exist or may be inaccessible. In either case...
}
return NO_TYPES;
}
示例3: size
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
@Override
public long size() throws IOException {
BasicFileAttributes attrs = readAttributes();
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory()) {
throw new IOException("can't read: is a directory");
} else if (attrs.isSymbolicLink()) {
throw new IOException("can't read: is a symbolic link");
}
return attrs.size();
}
示例4: getAttributes
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
/**
* Returns the attributes of the given file, taking into account whether
* the walk is following sym links is not. The {@code canUseCached}
* argument determines whether this method can use cached attributes.
*/
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
throws IOException
{
// if attributes are cached then use them if possible
if (canUseCached &&
(file instanceof BasicFileAttributesHolder) &&
(System.getSecurityManager() == null))
{
BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
return cached;
}
}
// attempt to get attributes of file. If fails and we are following
// links then a link target might not exist so get attributes of link
BasicFileAttributes attrs;
try {
attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
} catch (IOException ioe) {
if (!followLinks)
throw ioe;
// attempt to get attrmptes without following links
attrs = Files.readAttributes(file,
BasicFileAttributes.class,
LinkOption.NOFOLLOW_LINKS);
}
return attrs;
}
示例5: visitFile
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attr) {
if (attr.isSymbolicLink()) {
System.out.format("Symbolic link: %s ", file);
} else if (attr.isRegularFile()) {
System.out.format("Regular file: %s ", file);
} else {
System.out.format("Other: %s ", file);
}
System.out.println("(" + attr.size() + "bytes)");
return CONTINUE;
}
示例6: isSymbolicLink
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
public static boolean isSymbolicLink(String path) throws Exception {
BasicFileAttributes attrs = Files.readAttributes(FileSystems.getDefault().getPath(polishFilePath(path)), BasicFileAttributes.
class, LinkOption.NOFOLLOW_LINKS);
return attrs.isSymbolicLink();
}
示例7: isSymbolicLink
import java.nio.file.attribute.BasicFileAttributes; //导入方法依赖的package包/类
public static boolean isSymbolicLink(String path) throws Exception {
BasicFileAttributes attrs = Files.readAttributes(FileSystems.getDefault().getPath(polishFilePath(path)), BasicFileAttributes.
class, LinkOption.NOFOLLOW_LINKS);
return attrs.isSymbolicLink();
}