List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:company.gonapps.loghut.dao.TagDao.java
public void delete(TagDto tag) throws IOException { Path tagPath = Paths.get(settingDao.getSetting("tags.directory") + tag.getLocalPath()); rrwl.writeLock().lock();/*w w w. j ava2s .c om*/ try { Files.delete(tagPath); FileUtils.rmdir(tagPath.getParent(), new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path path) throws IOException { return !tagPathStringPattern.matcher(path.toString()).find(); } }); FileUtils.rmdir(tagPath.getParent().getParent(), new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path path) throws IOException { return (!tagMonthPattern.matcher(path.toString()).find()) || (!Files.isDirectory(path)); } }); FileUtils.rmdir(tagPath.getParent().getParent().getParent(), new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path path) throws IOException { return (!tagYearPattern.matcher(path.toString()).find()) || (!Files.isDirectory(path)); } }); } finally { rrwl.writeLock().unlock(); } }
From source file:org.tallison.cc.CCGetter.java
private void deleteTmp(Path tmp) { try {//w ww. j av a 2s .c o m Files.delete(tmp); } catch (IOException e1) { logger.error("Couldn't delete tmp file: " + tmp.toAbsolutePath()); } }
From source file:cc.arduino.contributions.packages.ContributionInstaller.java
public synchronized List<String> remove(ContributedPlatform contributedPlatform) { if (contributedPlatform == null || contributedPlatform.isBuiltIn()) { return new LinkedList<>(); }//w ww . j a v a2 s .co m List<String> errors = new LinkedList<>(); try { findAndExecutePreUninstallScriptIfAny(contributedPlatform.getInstalledFolder(), contributedPlatform.getParentPackage().isTrusted(), PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL)); } catch (IOException e) { errors.add(tr("Error running post install script")); } // Check if the tools are no longer needed for (ContributedTool tool : contributedPlatform.getResolvedTools()) { // Do not remove used tools if (BaseNoGui.indexer.isContributedToolUsed(contributedPlatform, tool)) continue; // Do not remove built-in tools if (tool.isBuiltIn()) continue; // Ok, delete the tool File destFolder = tool.getInstalledFolder(); FileUtils.recursiveDelete(destFolder); tool.setInstalled(false); tool.setInstalledFolder(null); // We removed the version folder (.../tools/TOOL_NAME/VERSION) // now try to remove the containing TOOL_NAME folder // (and silently fail if another version of the tool is installed) try { Files.delete(destFolder.getParentFile().toPath()); } catch (Exception e) { // ignore } } FileUtils.recursiveDelete(contributedPlatform.getInstalledFolder()); contributedPlatform.setInstalled(false); contributedPlatform.setInstalledFolder(null); return errors; }
From source file:org.eclipse.winery.repository.backend.filebased.FilebasedRepository.java
/** * {@inheritDoc}/* w w w . j a v a 2s.c o m*/ */ @Override public void putContentToFile(RepositoryFileReference ref, InputStream inputStream, MediaType mediaType) throws IOException { if (mediaType == null) { // quick hack for storing mime type called this method assert (ref.getFileName().endsWith(Constants.SUFFIX_MIMETYPE)); // we do not need to store the mime type of the file containing the mime type // information } else { this.setMimeType(ref, mediaType); } Path targetPath = this.ref2AbsolutePath(ref); // ensure that parent directory exists FileUtils.createDirectory(targetPath.getParent()); try { Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING); } catch (IllegalStateException e) { FilebasedRepository.logger.debug("Guessing that stream with length 0 is to be written to a file", e); // copy throws an "java.lang.IllegalStateException: Stream already closed" if the // InputStream contains 0 bytes // For instance, this case happens if SugarCE-6.4.2.zip.removed is tried to be uploaded // We work around the Java7 issue and create an empty file if (Files.exists(targetPath)) { // semantics of putContentToFile: existing content is replaced without notification Files.delete(targetPath); } Files.createFile(targetPath); } }
From source file:org.carcv.impl.core.io.FFMPEGVideoHandlerIT.java
/** * Test method for {@link org.carcv.impl.core.io.FFMPEGVideoHandler#createVideo(java.nio.file.Path, int)}. * * @throws IOException/* w w w. ja va2 s. c o m*/ */ @Test public void testCreateVideo() throws IOException { FFMPEGVideoHandler.copyCarImagesToDir(entry.getCarImages(), videoDir); Path video = new FFMPEGVideoHandler().createVideo(videoDir, FFMPEGVideoHandler.defaultFrameRate); assertTrue("Generated video file doesn't exist.", Files.exists(video)); Files.delete(video); }
From source file:dk.dma.ais.downloader.QueryService.java
/** * Deletes all the file of the client folder *///w ww .j a v a 2s .c om @RequestMapping(value = "/delete-all/{clientId}", method = RequestMethod.GET) @ResponseBody public String deleteFiles(@PathVariable("clientId") String clientId, HttpServletResponse response) throws IOException { int deletedFiles = 0; Path path = repoRoot.resolve(clientId); if (Files.notExists(path) || !Files.isDirectory(path)) { log.log(Level.WARNING, "Failed deleting files in " + path); response.setStatus(404); return "Failed deleting files in " + clientId; } try { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { log.info("Deleting repo file :" + file); Files.delete(file); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.log(Level.SEVERE, "Failed cleaning up dir: " + path); return "Failed deleting files in " + clientId; } return "Deleted files in dir " + clientId; }
From source file:org.knime.ext.textprocessing.nodes.misc.bratdocumentwriter.BratDocumentWriterNodeModel.java
/** * Delete local file./*from w ww . j a v a 2s. c om*/ * * @param filepath the to be deleted file path * @throws IOException if an I/O error occurs */ private static void deleteFile(final String filepath) throws IOException { final Path path = Paths.get(filepath); // check if file exists, if yes then delete if (Files.exists(path)) { Files.delete(path); } // if file does not exist anyway, do nothing }
From source file:com.github.wasiqb.coteafs.appium.service.AppiumServer.java
/** * @author wasiq.bhamla/*ww w . j a va2 s. com*/ * @since Oct 27, 2017 3:00:49 PM */ private void setLogFile() { final String logFilePath = this.setting.getLogFilePath(); if (logFilePath != null) { final File logFile = new File(logFilePath); try { if (logFile.exists()) { Files.delete(logFile.toPath()); } } catch (final IOException e) { fail(AppiumServerLogFileError.class, "Error while deleting log file!", e); } this.builder = this.builder.withLogFile(logFile); } }
From source file:de.huberlin.wbi.cuneiform.core.cre.LocalThread.java
public static void deleteIfExists(Path f) throws IOException { if (!Files.exists(f, LinkOption.NOFOLLOW_LINKS)) return;/*from ww w . j a va 2 s .co m*/ if (Files.isDirectory(f)) try (DirectoryStream<Path> stream = Files.newDirectoryStream(f)) { for (Path p : stream) deleteIfExists(p); } Files.delete(f); }
From source file:org.apache.jena.atlas.io.IO.java
/** Delete everything from a {@code Path} start point, including the path itself. * This function works on files or directories. * This function does not follow symbolic links. *//*from w w w . ja va 2 s . co m*/ public static void deleteAll(Path start) { // Walks down the tree and delete directories on the way backup. try { Files.walkFileTree(start, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); } catch (IOException ex) { IO.exception(ex); return; } }