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