62,635
社区成员




public static void main(String[] args){
ArrayList lsFinaDirs = new ArrayList();
getFinalDirs("G:\\workshop\\IDM",lsFinaDirs);
for(Object dirs:lsFinaDirs){
System.out.println("最终子目录:"+dirs.toString());
}
}
public static void getFinalDirs(String rootPath,ArrayList lsDirs){
File curDir = new File(rootPath);
boolean isFinalFlag = false;
if(curDir.isFile()){
return;
}
if(!curDir.isFile()){
isFinalFlag = true;
String[] subDir = curDir.list();
if(subDir.length>=1){
for(String subDirPath:subDir){
File subDirFile = new File(rootPath+File.separator+subDirPath);
//有子目录,则当前目录不是最终目录,递归处理
if(!subDirFile.isFile()){
isFinalFlag= false;
getFinalDirs(rootPath+File.separator+subDirPath,lsDirs);
}
}
}
}
//如果是最终目录,加入结果列表
if(isFinalFlag){
lsDirs.add(rootPath);
}
}
import java.util.Arrays;
import java.util.ArrayList;
public class Test{
public static void main(String[] args){
String[] uris = {
"E:\\KJK\\BH04\\toRST",
"E:\\KJK\\BH04\\toRST\\RST03",
"E:\\KJK\\BH04\\toRST\\RST03\\01",
"E:\\KJK\\BH04\\toRST\\RST03\\02",
"E:\\KJK\\BH04\\toRST\\RST03\\03",
"E:\\KJK\\BH04\\toRST\\RST03\\04",
"E:\\KJK\\BH04\\toRST\\RST03\\06",
"E:\\KJK\\BH04\\toRST\\RST03\\07",
"E:\\KJK\\BH04"
};
Arrays.sort(uris);
ArrayList<String> list = new ArrayList<>();
for(int i = 0,j = 0 ; i < uris.length - 1 ; i ++){
j = i + 1;
if(uris[j].startsWith(uris[i])){
continue;
}
list.add(uris[i]);
}
for(String uri : list){
System.out.println(uri);
}
}
}