TreeNode loadFilePaths(String rootPath)
{
File path=new File(rootPath);
DefaultMutableTreeNode root=new
DefaultMutableTreeNode(path.getName().trim());
DefaultTreeModel model=new DefaultTreeModel(root);
File[] childsOfPath=path.listFiles();
for(int i=0;i<=childsOfPath.length-1;i++){
if( !childsOfPath[i].isHidden()){ //判断一下是否是隐藏文件就行了
String name=childsOfPath[i].getName().trim();
if(childsOfPath[i].isDirectory()){
DefaultMutableTreeNode childRoot;
childRoot=(DefaultMutableTreeNode)
loadFilePaths(childsOfPath[i].getAbsolutePath());
if(childRoot.getChildCount()>0) root.add(childRoot);
}
else{
DefaultMutableTreeNode childRoot=new DefaultMutableTreeNode(name);
root.add(childRoot);
}
}
}
return root;
}
{
File path=new File(rootPath);
DefaultMutableTreeNode root=new
DefaultMutableTreeNode(path.getName().trim());
DefaultTreeModel model=new DefaultTreeModel(root);
File[] childsOfPath=path.listFiles();
for(int i=0;i<=childsOfPath.length-1;i++){
if( !childsOfPath[i].isHidden()){ //判断一下是否是隐藏文件就行了
String name=childsOfPath[i].getName().trim();
if(childsOfPath[i].isDirectory()){
DefaultMutableTreeNode childRoot;
childRoot=(DefaultMutableTreeNode)
loadFilePaths(childsOfPath[i].getAbsolutePath());
if(childRoot.getChildCount()>0) root.add(childRoot);
}
else{
DefaultMutableTreeNode childRoot=new DefaultMutableTreeNode(name);
root.add(childRoot);
}
}
}
return root;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货