本文整理汇总了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;
}
});
}
示例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();
}
}
示例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;
}
示例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;
}
});
}
示例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);
}
});
}
示例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;
}
示例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;
}
示例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;
}
});
}
示例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;
}
});
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
});
}
示例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;
}
示例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;
}
});
}
}