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