ZKTools { public static String[] getTree(ZooKeeper zk, String path) throws Exception { if (zk.exists(path, false) == null) { return new String[0]; } List<String> dealList = new ArrayList<>(); dealList.add(path); int index = 0; while (index < dealList.size()) { String tempPath = dealList.get(index); List<String> children = zk.getChildren(tempPath, false); if (tempPath.equalsIgnoreCase("/") == false) { tempPath = tempPath + "/"; } Collections.sort(children); for (int i = children.size() - 1; i >= 0; i--) { dealList.add(index + 1, tempPath + children.get(i)); } index++; } return dealList.toArray(new String[0]); }  static void createPath(ZooKeeper zk, String path, CreateMode createMode, List<ACL> acl); static void printTree(ZooKeeper zk, String path, Writer writer, String lineSplitChar); static void deleteTree(ZooKeeper zk, String path); static String[] getTree(ZooKeeper zk, String path);  }
@Test public void getTree() throws Exception { String[] paths = ZKTools.getTree(zooKeeper, "/schedule"); for (int i = paths.length -1; i >= 0; i--) { System.out.println(paths[i]); } }