在java中目录被看做_在java中查看用于创建,修改和更改的目录和子目录

我已经为目录C中的一些代码进行了更改:/

java / newfolder它运行良好.我在下面给出了.

import java.nio.file.*;

import java.util.List;

public class DirectoryWatchExample {

public static void testForDirectoryChange(Path myDir){

try {

WatchService watcher = myDir.getFileSystem().newWatchService();

myDir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE,

StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);

WatchKey watckKey = watcher.take();

List> events = watckKey.pollEvents();

for (WatchEvent event : events) {

if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {

System.out.println("Created: " + event.context().toString());

}

if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) {

System.out.println("Delete: " + event.context().toString());

}

if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {

System.out.println("Modify: " + event.context().toString());

}

}

} catch (Exception e) {

System.out.println("Error: " + e.toString());

}

}

public static void main (String[] args) {

Path myDir = Paths.get("c:/java/newfolder/");

//define a folder root

testForDirectoryChange(myDir);

}

}

现在我只看目录.但我只需要观看所有子目录.

例如:c:/ java / newfolder / folder1,c:/ java / newfolder / folder2,c:/ java / newfolder / folder3 ……等

我给出了子目录上面的例子

c:/java/newfolder/*..

我需要观看所有子目录给我一些解决方案吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值