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


Java StandardCopyOption.REPLACE_EXISTING属性代码示例

本文整理汇总了Java中java.nio.file.StandardCopyOption.REPLACE_EXISTING属性的典型用法代码示例。如果您正苦于以下问题:Java StandardCopyOption.REPLACE_EXISTING属性的具体用法?Java StandardCopyOption.REPLACE_EXISTING怎么用?Java StandardCopyOption.REPLACE_EXISTING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.nio.file.StandardCopyOption的用法示例。


在下文中一共展示了StandardCopyOption.REPLACE_EXISTING属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeToDirectory

/**
 * Write the dex program resources and proguard resource to @code{directory}.
 */
public void writeToDirectory(Path directory, OutputMode outputMode) throws IOException {
  if (outputMode == OutputMode.Indexed) {
    for (Path path : Files.list(directory).collect(Collectors.toList())) {
      if (isClassesDexFile(path)) {
        Files.delete(path);
      }
    }
  }
  CopyOption[] options = new CopyOption[] {StandardCopyOption.REPLACE_EXISTING};
  try (Closer closer = Closer.create()) {
    List<Resource> dexProgramSources = getDexProgramResources();
    for (int i = 0; i < dexProgramSources.size(); i++) {
      Path filePath = directory.resolve(outputMode.getOutputPath(dexProgramSources.get(i), i));
      if (!Files.exists(filePath.getParent())) {
        Files.createDirectories(filePath.getParent());
      }
      Files.copy(closer.register(dexProgramSources.get(i).getStream()), filePath, options);
    }
  }
}
 
开发者ID:inferjay,项目名称:r8,代码行数:23,代码来源:AndroidApp.java

示例2: fromCopyOptions

static Flags fromCopyOptions(CopyOption... options) {
    Flags flags = new Flags();
    flags.followLinks = true;
    for (CopyOption option: options) {
        if (option == StandardCopyOption.REPLACE_EXISTING) {
            flags.replaceExisting = true;
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.followLinks = false;
            continue;
        }
        if (option == StandardCopyOption.COPY_ATTRIBUTES) {
            // copy all attributes but only fail if basic attributes
            // cannot be copied
            flags.copyBasicAttributes = true;
            flags.copyPosixAttributes = true;
            flags.copyNonPosixAttributes = true;
            flags.failIfUnableToCopyBasic = true;
            continue;
        }
        if (ExtendedOptions.INTERRUPTIBLE.matches(option)) {
            flags.interruptible = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException("Unsupported copy option");
    }
    return flags;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:UnixCopyFile.java

示例3: fromMoveOptions

static Flags fromMoveOptions(CopyOption... options) {
    Flags flags = new Flags();
    for (CopyOption option: options) {
        if (option == StandardCopyOption.ATOMIC_MOVE) {
            flags.atomicMove = true;
            continue;
        }
        if (option == StandardCopyOption.REPLACE_EXISTING) {
            flags.replaceExisting = true;
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            // ignore
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException("Unsupported copy option");
    }

    // a move requires that all attributes be copied but only fail if
    // the basic attributes cannot be copied
    flags.copyBasicAttributes = true;
    flags.copyPosixAttributes = true;
    flags.copyNonPosixAttributes = true;
    flags.failIfUnableToCopyBasic = true;
    return flags;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:UnixCopyFile.java

示例4: copyFile

public static void copyFile(String fn_src, String fn_dest) throws Exception {
    // overwrite if fn_dest exists
    CopyOption[] options = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING};
    Files.copy(new File(fn_src).toPath(), new File(fn_dest).toPath(), options);
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:5,代码来源:Util.java


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