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


Java BasicFileAttributes.isSymbolicLink方法代码示例

本文整理汇总了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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:MoreFiles.java

示例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;
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:14,代码来源:FileNode.java

示例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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:MoreFiles.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:FileTreeWalker.java

示例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;
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:14,代码来源:PrintFiles.java

示例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();
}
 
开发者ID:DataAgg,项目名称:DAFramework,代码行数:7,代码来源:SysToolkit.java

示例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();
}
 
开发者ID:DataAgg,项目名称:DaUtil,代码行数:7,代码来源:SysToolkit.java


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