当前位置: 首页>>代码示例>>Java>>正文


Java FileVisitResult类代码示例

本文整理汇总了Java中java.nio.file.FileVisitResult的典型用法代码示例。如果您正苦于以下问题:Java FileVisitResult类的具体用法?Java FileVisitResult怎么用?Java FileVisitResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileVisitResult类属于java.nio.file包,在下文中一共展示了FileVisitResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recursiveDelete

import java.nio.file.FileVisitResult; //导入依赖的package包/类
/**
 *
 * @param directory
 * @throws IOException
 */
public static void recursiveDelete(Path directory) throws IOException {
    Files.walkFileTree(directory, 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 exc) throws IOException {

            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}
 
开发者ID:CIRDLES,项目名称:Squid,代码行数:27,代码来源:FileUtilities.java

示例2: deleteFiles

import java.nio.file.FileVisitResult; //导入依赖的package包/类
public static void deleteFiles (String path){    
	 try {
		 Path directory = Paths.get(path);
		 Files.walkFileTree(directory, 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 exc) throws IOException {
		        Files.delete(dir);
		        return FileVisitResult.CONTINUE;
		    }
		 });
	} catch (IOException e) {
		e.printStackTrace();
	}      
}
 
开发者ID:KayDeeTee,项目名称:Hollow-Knight-SaveManager,代码行数:21,代码来源:Listeners.java

示例3: deleteDirectory

import java.nio.file.FileVisitResult; //导入依赖的package包/类
/**
 * Deletes a directory recursively
 *
 * @param directory
 * @return true if deletion succeeds, false otherwise
 */
public static boolean deleteDirectory(Path directory) {
    if (directory != null) {
        try {
            Files.walkFileTree(directory, 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 exc) throws IOException {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ignored) {
            return false;
        }
    }
    return true;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:29,代码来源:FileUploadHelper.java

示例4: delete

import java.nio.file.FileVisitResult; //导入依赖的package包/类
static void delete(Path root) throws IOException {
    if (!Files.exists(root))
        return;
    Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile(Path f, BasicFileAttributes a)
                     throws IOException {
                 Files.delete(f);
                 return FileVisitResult.CONTINUE;
             }

             @Override
             public FileVisitResult postVisitDirectory(Path dir, IOException e)
                     throws IOException {
                 if (e != null)
                     throw e;
                 if (!dir.equals(root))
                     Files.delete(dir);
                 return FileVisitResult.CONTINUE;
             }
        });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ClasspathDependencies.java

示例5: deleteDir

import java.nio.file.FileVisitResult; //导入依赖的package包/类
/**
 * Deletes directory along with all inner files.
 *
 * @param path to directory.
 * @throws IOException if there are errors during deleting.
 */
public static void deleteDir(Path path) throws IOException {
    if (!Files.exists(path)) {
        return;
    }
    Files.walkFileTree(path, 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 exc) throws IOException {
            Files.delete(dir);
            return super.postVisitDirectory(dir, exc);
        }
    });
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:23,代码来源:FileUtils.java

示例6: execute

import java.nio.file.FileVisitResult; //导入依赖的package包/类
@Override
public boolean execute() {
	File folder=CacheManager.getRootCacheInstance().getPath();
	//System.gc();
	try {
		Files.walkFileTree(folder.toPath(), 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 exc) throws IOException {
				   Files.delete(dir);
				   return FileVisitResult.CONTINUE;
			   }

		   });
	} catch (IOException e) {
		logger.error(e.getMessage());
		return false;
	}
   	super.notifyEvent(new SumoActionEvent(SumoActionEvent.ENDACTION,"cache cleaned...", -1));
	return true;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:27,代码来源:ClearCacheAction.java

示例7: listClassNamesInPackage

import java.nio.file.FileVisitResult; //导入依赖的package包/类
static List<String> listClassNamesInPackage(String packageName) throws Exception {
	List<String> classes = new ArrayList<>();
	Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(packageName.replace('.', File.separatorChar));
	if (!resources.hasMoreElements()) {
		throw new IllegalStateException("No package found: " + packageName);
	}
	PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:*.class");
	while (resources.hasMoreElements()) {
		URL resource = resources.nextElement();
		Files.walkFileTree(Paths.get(resource.toURI()), new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
				if (pathMatcher.matches(path.getFileName())) {
					try {
						String className = Paths.get(resource.toURI()).relativize(path).toString().replace(File.separatorChar, '.');
						classes.add(packageName + '.' + className.substring(0, className.length() - 6));
					} catch (URISyntaxException e) {
						throw new IllegalStateException(e);
					}
				}
				return FileVisitResult.CONTINUE;
			}
		});
	}
	return classes;
}
 
开发者ID:Devskiller,项目名称:jpa2ddl,代码行数:27,代码来源:FileResolver.java

示例8: removeRecursive

import java.nio.file.FileVisitResult; //导入依赖的package包/类
public static void removeRecursive(final Path path) throws IOException {
  Files.walkFileTree(
      path,
      new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
            throws IOException {
          Files.deleteIfExists(file);
          return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
            throws IOException {
          Files.deleteIfExists(dir);
          return FileVisitResult.CONTINUE;
        }
      });
}
 
开发者ID:spotify,项目名称:bazel-tools,代码行数:20,代码来源:PathUtils.java

示例9: importSketchFiles

import java.nio.file.FileVisitResult; //导入依赖的package包/类
private void importSketchFiles( Path sketchDirPath ) throws IOException {
    if ( !copyingFiles ) return;
    Files.walkFileTree(sketchDirPath, new CopyingFileVisitor(sketchDirPath, getSourceFilesDirectoryPath(), PROJECT_SOURCE_FILE_MATCHER) {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
            if ( file.toString().endsWith(".ino.cpp") ) {
                String filename = file.getFileName().toString();
                String newFilename = filename.replace(".ino.cpp", ".cpp");
                Path targetFilePath = target.resolve( source.relativize( Paths.get(file.getParent().toString(), newFilename) ) );
                copyFile( file, targetFilePath );
                try {
                    removeLineDirectives( targetFilePath);
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            } else { 
                copyFile( file, target.resolve( source.relativize(file) ) );
            }
            return CONTINUE;
        }            
    });
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:23,代码来源:ChipKitProjectImporter.java

示例10: processSubevents

import java.nio.file.FileVisitResult; //导入依赖的package包/类
/**
 * Starts watching the subdirectories of the provided directory for changes.
 * @param root Root directory of the subdirectories to register.
 * @throws IOException If a subdirectory cannot be registered.
 * @checkstyle RequireThisCheck (20 lines)
 * @checkstyle NonStaticMethodCheck (20 lines)
 */
private void processSubevents(final Path root) throws IOException {
    try {
        Files.walkFileTree(
            root,
            new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(
                    final Path subdir,
                    final BasicFileAttributes attrs
                ) throws IOException {
                    registerDirectory(subdir);
                    return FileVisitResult.CONTINUE;
                }
            });
    } catch (final IOException ex) {
        throw new IOException("Failed to register subdirectories", ex);
    }
}
 
开发者ID:driver733,项目名称:VKMusicUploader,代码行数:26,代码来源:WatchDirs.java

示例11: preVisitDirectory

import java.nio.file.FileVisitResult; //导入依赖的package包/类
@Override
public FileVisitResult preVisitDirectory(Path dir,
		BasicFileAttributes attrs) throws IOException {
	String dirName = dir.toFile().getName();
	long directorySize = getDirectorySize(dir.toFile());

	printAttributes(getPermissions(dir), directorySize,
			getFormattedDate(dir), dirName);
	return FileVisitResult.CONTINUE;
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:11,代码来源:LsShellCommand.java

示例12: postVisitDirectory

import java.nio.file.FileVisitResult; //导入依赖的package包/类
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException
{
	if( exc != null )
	{
		success = false;
		LOGGER.warn("Folder traversal failed.  Could not traverse " + dir.toString());
	}
	try
	{
		Files.delete(dir);
	}
	catch( Exception e )
	{
		success = false;
		LOGGER.warn("Folder deletion failed.  Could not delete " + dir.toString());
	}
	return FileVisitResult.CONTINUE;
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:FileUtils.java

示例13: deleteTmpDir

import java.nio.file.FileVisitResult; //导入依赖的package包/类
@After
public void deleteTmpDir() throws IOException {
    Files.walkFileTree(this.tmpDir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult postVisitDirectory(final Path theDir, final IOException e) throws IOException {
            if (e != null) return TERMINATE;
            Files.delete(theDir);
            return CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(final Path theFile, final BasicFileAttributes attrs) throws IOException {
            Files.delete(theFile);
            return CONTINUE;
        }
    });
}
 
开发者ID:dzuvic,项目名称:jtsgen,代码行数:18,代码来源:TsGenProcessorTmpDirTest.java

示例14: preVisitDirectory

import java.nio.file.FileVisitResult; //导入依赖的package包/类
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
    final String d = dir.getFileName().toString();
    final String abs = dir.toAbsolutePath().toString();

    if (d.startsWith(".")) {
        return SKIP_SUBTREE;
    } else if (abs.equals(workspacePath+"/clj-out")) {
        return SKIP_SUBTREE;
    } else if (abs.equals(workspacePath+"/target")) {
        return SKIP_SUBTREE;
    } else if (abs.equals(workspacePath+"/buck-out")) {
        return SKIP_SUBTREE;
    }
    find(dir);
    return CONTINUE;
}
 
开发者ID:nfisher,项目名称:cljbuck,代码行数:18,代码来源:PathTraversal.java

示例15: tearDown

import java.nio.file.FileVisitResult; //导入依赖的package包/类
@Override
protected void tearDown() throws Exception {
  if (tempDir != null) {
    // delete tempDir and its contents
    Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        Files.deleteIfExists(file);
        return FileVisitResult.CONTINUE;
      }

      @Override
      public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
        if (exc != null) {
          return FileVisitResult.TERMINATE;
        }
        Files.deleteIfExists(dir);
        return FileVisitResult.CONTINUE;
      }
    });
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:23,代码来源:MoreFilesTest.java


注:本文中的java.nio.file.FileVisitResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。