本文整理匯總了Java中java.nio.file.StandardOpenOption.TRUNCATE_EXISTING屬性的典型用法代碼示例。如果您正苦於以下問題:Java StandardOpenOption.TRUNCATE_EXISTING屬性的具體用法?Java StandardOpenOption.TRUNCATE_EXISTING怎麽用?Java StandardOpenOption.TRUNCATE_EXISTING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.nio.file.StandardOpenOption
的用法示例。
在下文中一共展示了StandardOpenOption.TRUNCATE_EXISTING屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeToZip
/**
* Write the dex program resources to @code{archive} and the proguard resource as its sibling.
*/
public void writeToZip(Path archive, OutputMode outputMode) throws IOException {
OpenOption[] options =
new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING};
try (Closer closer = Closer.create()) {
try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(archive, options))) {
List<Resource> dexProgramSources = getDexProgramResources();
for (int i = 0; i < dexProgramSources.size(); i++) {
ZipEntry zipEntry = new ZipEntry(outputMode.getOutputPath(dexProgramSources.get(i), i));
byte[] bytes =
ByteStreams.toByteArray(closer.register(dexProgramSources.get(i).getStream()));
zipEntry.setSize(bytes.length);
out.putNextEntry(zipEntry);
out.write(bytes);
out.closeEntry();
}
}
}
}
示例2: getOpenOptions
static OpenOption[] getOpenOptions(boolean append) {
OpenOption[] defaultOpenOptions = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING};
OpenOption[] appendOpenOptions = {StandardOpenOption.APPEND};
return append ? appendOpenOptions : defaultOpenOptions;
}