本文整理了Java中java.nio.file.Files.delete()
方法的一些代码示例,展示了Files.delete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.delete()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:delete
暂无
代码示例来源:origin: neo4j/neo4j
@Override
public void deleteFileOrThrow( File file ) throws IOException
{
Files.delete( file.toPath() );
}
代码示例来源:origin: apache/ignite
/**
*
*/
private void cleanupMarshallerFileStore() throws IOException {
Path marshCache = Paths.get(TMP_DIR, "marshaller");
for (File file : marshCache.toFile().listFiles())
Files.delete(file.toPath());
Files.deleteIfExists(marshCache);
}
代码示例来源:origin: apache/nifi
protected void delete(final File file) throws IOException {
Files.delete(file.toPath());
}
代码示例来源:origin: apache/flink
java.nio.file.Path parent = target.getParentFile().toPath();
java.nio.file.Path targetPath = target.toPath();
Files.createFile(target.toPath());
try (FileWriter fw = new FileWriter(target)) {
fw.write(json);
Files.delete(new File(webOverviewDir, jobID + JSON_FILE_ENDING).toPath());
} catch (IOException ioe) {
LOG.debug("Could not delete file from overview directory.", ioe);
代码示例来源:origin: apache/incubator-druid
public void delete(final File file)
{
synchronized (files) {
if (files.contains(file)) {
try {
Files.delete(file.toPath());
}
catch (IOException e) {
log.warn(e, "Cannot delete file: %s", file);
}
files.remove(file);
}
}
}
代码示例来源:origin: apache/drill
@Override
public void action(URL url) {
File file = new File(url.getPath());
try {
Files.delete(file.toPath());
} catch (IOException e) {
logger.error("There was an error during file {} removing.", url.getFile(), e);
}
}
};
代码示例来源:origin: atomix/atomix
/**
* Deletes file in the storage directory that match the given predicate.
*/
private void deleteFiles(Predicate<File> predicate) {
directory.mkdirs();
// Iterate through all files in the storage directory.
for (File file : directory.listFiles(f -> f.isFile() && predicate.test(f))) {
try {
Files.delete(file.toPath());
} catch (IOException e) {
// Ignore the exception.
}
}
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
public static File createSymbolicLink( File symlink, File target )
throws IOException
{
Path link = symlink.toPath();
if ( Files.exists( link, LinkOption.NOFOLLOW_LINKS ) )
{
Files.delete( link );
}
link = Files.createSymbolicLink( link, target.toPath() );
return link.toFile();
}
代码示例来源:origin: atomix/atomix
/**
* Deletes the underlying file.
*/
public void delete() {
try {
close();
Files.delete(file.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: atomix/atomix
/**
* Deletes the underlying file.
*/
public void delete() {
try {
close();
Files.delete(file.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/ignite
/**
* Cleanup checkpoint directory from all temporary files.
*/
@Override public void cleanupTempCheckpointDirectory() throws IgniteCheckedException {
try {
try (DirectoryStream<Path> files = Files.newDirectoryStream(cpDir.toPath(), TMP_FILE_MATCHER::matches)) {
for (Path path : files)
Files.delete(path);
}
}
catch (IOException e) {
throw new IgniteCheckedException("Failed to cleanup checkpoint directory from temporary files: " + cpDir, e);
}
}
代码示例来源:origin: apache/ignite
/**
* Removes the specified directory.
*
* @param path Path to the directory.
*/
public static void deleteDirectory(Path path) {
File file = path.toFile();
if (file.isDirectory()) {
File[] children = file.listFiles();
if (children != null) {
for (File child : children)
deleteDirectory(child.toPath());
}
}
try {
Files.delete(path);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/incubator-druid
private void cleanupAssignedTask(Task task)
{
assignedTasks.remove(task.getId());
File taskFile = new File(getAssignedTaskDir(), task.getId());
try {
Files.delete(taskFile.toPath());
}
catch (IOException ex) {
log.error(ex, "Failed to delete assigned task from disk at [%s].", taskFile);
}
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories.
* <p>
* The difference between File.delete() and this method are:
* <ul>
* <li>A directory to be deleted does not have to be empty.</li>
* <li>No exceptions are thrown when a file or directory cannot be deleted.</li>
* </ul>
*
* @param file file or directory to delete, can be {@code null}
* @return {@code true} if the file or directory was deleted, otherwise {@code false}
*/
public static boolean deleteQuietly(@Nullable File file) {
if (file == null) {
return false;
}
try {
if (file.isDirectory()) {
deleteDirectory(file);
} else {
Files.delete(file.toPath());
}
return true;
} catch (IOException | SecurityException ignored) {
return false;
}
}
代码示例来源:origin: real-logic/agrona
/**
* Delete file only if it already exists.
*
* @param file to delete
*/
public static void deleteIfExists(final File file)
{
if (file.exists())
{
try
{
Files.delete(file.toPath());
}
catch (final IOException ex)
{
LangUtil.rethrowUnchecked(ex);
}
}
}
代码示例来源:origin: apache/ignite
/**
* Removes checkpoint start/end files belongs to given {@code cpEntry}.
*
* @param cpEntry Checkpoint entry.
*
* @throws IgniteCheckedException If failed to delete.
*/
private void removeCheckpointFiles(CheckpointEntry cpEntry) throws IgniteCheckedException {
Path startFile = new File(cpDir.getAbsolutePath(), checkpointFileName(cpEntry, CheckpointEntryType.START)).toPath();
Path endFile = new File(cpDir.getAbsolutePath(), checkpointFileName(cpEntry, CheckpointEntryType.END)).toPath();
try {
if (Files.exists(startFile))
Files.delete(startFile);
if (Files.exists(endFile))
Files.delete(endFile);
}
catch (IOException e) {
throw new StorageException("Failed to delete stale checkpoint files: " + cpEntry, e);
}
}
代码示例来源:origin: atomix/atomix
/**
* Deletes the snapshot file.
*/
@Override
public void delete() {
LOGGER.debug("Deleting {}", this);
Path path = file.file().toPath();
if (Files.exists(path)) {
try {
Files.delete(file.file().toPath());
} catch (IOException e) {
}
}
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void cleanupPersistentSpace(CacheConfiguration cacheConfiguration) throws IgniteCheckedException {
try {
File cacheWorkDir = cacheWorkDir(cacheConfiguration);
if(!cacheWorkDir.exists())
return;
try (DirectoryStream<Path> files = newDirectoryStream(cacheWorkDir.toPath(),
new DirectoryStream.Filter<Path>() {
@Override public boolean accept(Path entry) throws IOException {
return entry.toFile().getName().endsWith(FILE_SUFFIX);
}
})) {
for (Path path : files)
delete(path);
}
}
catch (IOException e) {
throw new IgniteCheckedException("Failed to cleanup persistent directory: ", e);
}
}
代码示例来源:origin: apache/kafka
@After
public void tearDown() throws Exception {
Files.delete(jaasConfigFile.toPath());
}
代码示例来源:origin: kairosdb/kairosdb
Files.delete(zipFile.toPath());
内容来源于网络,如有侵权,请联系作者删除!