本文整理汇总了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);
}
}
}
示例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;
}
示例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;
}
示例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);
}