List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:de.ks.option.properties.PropertiesOptionSource.java
public static void cleanup() { String path = getPropertiesFile(); if (new File(path).exists()) { try {/*from ww w. j av a 2 s.c o m*/ Files.delete(Paths.get(path)); } catch (IOException e) { log.error("Could not clean up {}", path, e); } } }
From source file:de.teamgrit.grit.report.PdfConcatenator.java
/** * Concatinates pdfs generated {@link TexGenerator}. * * @param folderWithPdfs//from www . jav a 2 s . co m * the folder with pdfs * @param outPath * the out path * @param exerciseName * the context * @param studentsWithoutSubmissions * list of students who did not submit any solution * @return the path to the created PDF * @throws IOException * Signals that an I/O exception has occurred. */ protected static Path concatPDFS(Path folderWithPdfs, Path outPath, String exerciseName, List<Student> studentsWithoutSubmissions) throws IOException { if ((folderWithPdfs == null) || !Files.isDirectory(folderWithPdfs)) { throw new IOException("The Path doesn't point to a Folder"); } File file = new File(outPath.toFile(), "report.tex"); if (Files.exists(file.toPath(), LinkOption.NOFOLLOW_LINKS)) { Files.delete(file.toPath()); } file.createNewFile(); writePreamble(file, exerciseName); writeMissingStudents(file, studentsWithoutSubmissions); writeFiles(file, folderWithPdfs); writeClosing(file); PdfCreator.createPdfFromPath(file.toPath(), outPath); return file.toPath(); }
From source file:gndata.app.ui.main.MenuCtrlTest.java
@After public void tearDown() throws Exception { if (Files.exists(tmpPath)) { FileUtils.deleteDirectory(tmpPath.toFile()); }//from w w w .j a v a 2s.c o m if (Files.exists(tmpConf)) { Files.delete(tmpConf); } }
From source file:org.apache.htrace.impl.TestDroppedSpans.java
@BeforeClass public static void afterClass() throws IOException { if (tempDir != null) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(tempDir)) { for (final Iterator<Path> it = stream.iterator(); it.hasNext();) { Files.delete(it.next()); }/* w ww. jav a 2s .co m*/ } Files.delete(tempDir); tempDir = null; } }
From source file:de.teamgrit.grit.report.PlainGenerator.java
/** * This method creates a plain-text file from a SubmissionObj instance. * /* w w w .j a va 2s .c o m*/ * @param submission * A SubmissionObj containing the information that the content * gets generated from. * @param outdir * the output directory * @param courseName * the name of the Course * @param exerciseName * the name of the exercise * @return The Path to the created plain-text file. * @throws IOException * If something goes wrong when writing. */ public static Path generatePlain(final Submission submission, final Path outdir, String courseName, String exerciseName) throws IOException { final File location = outdir.toFile(); File outputFile = new File(location, submission.getStudent().getName() + ".report.txt"); if (Files.exists(outputFile.toPath(), LinkOption.NOFOLLOW_LINKS)) { Files.delete(outputFile.toPath()); } outputFile.createNewFile(); writeHeader(outputFile, submission, courseName, exerciseName); writeOverview(outputFile, submission); writeTestResult(outputFile, submission); // if there are compile errors, put these in the text file instead of // JUnit Test result CheckingResult checkingResult = submission.getCheckingResult(); if (checkingResult.getCompilerOutput().compilerStreamBroken()) { writeCompilerErrors(outputFile, submission); } else { TestOutput testResults = checkingResult.getTestResults(); if ((testResults.getPassedTestCount() < testResults.getTestCount()) && testResults.getDidTest()) { writeFailedTests(outputFile, submission); } } writeCompilerOutput(outputFile, submission); return outputFile.toPath(); }
From source file:org.mule.modules.hdfs.automation.functional.CopyToLocalFileTestCases.java
@After public void tearDown() throws Exception { getConnector().deleteFile(MYFILE_PATH); Files.delete(Paths.get(LOCAL_TAGET_PATH)); Path localTarget = Paths.get(LOCAL_TAGET_PATH); Files.delete(localTarget.resolveSibling("." + localTarget.getFileName().toString() + ".crc")); }
From source file:net.sourceforge.pmd.docs.RuleDocGeneratorTest.java
@After public void cleanup() throws IOException { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override/*from w ww .ja va2 s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); }
From source file:org.global.canvas.services.impl.StorageServiceImpl.java
@PostConstruct public void init() throws IOException { Path directory = Paths.get("/tmp/canvas/"); Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override/*from ww w .j a v a2s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); System.out.println("Dir deleted.. let's create it now.."); File dir = new File("/tmp/canvas/"); boolean created = dir.mkdir(); }
From source file:org.wildfly.plugin.server.Archives.java
/** * Recursively deletes a directory. If the directory does not exist it's ignored. * * @param dir the directory/*from w ww .j a v a 2 s . c o m*/ * * @throws java.lang.IllegalArgumentException if the argument is not a directory */ public static void deleteDirectory(final Path dir) throws IOException { if (Files.notExists(dir)) return; if (!Files.isDirectory(dir)) { throw new IllegalArgumentException(String.format("Path '%s' is not a directory.", dir)); } Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { Files.delete(file); return CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException { Files.delete(dir); return CONTINUE; } }); }
From source file:com.kixeye.chassis.bootstrap.TestUtils.java
public static void delete(Set<Path> paths) { for (Path path : paths) { try {//from w w w . ja va 2 s. c o m Files.delete(path); } catch (IOException e) { throw new RuntimeException(e); } } }