java 获取某路径下的子文件/子路径

/**
     * 获取某路径下的子文件
     * */
    public static List<String> getSubFile(String path){
        List<String> subFile = new ArrayList<>();
        File file=new File(path);
        //确保该路径存在
        if(file.exists()){
            File[] tempList = file.listFiles();
            //有子文件时
            if (tempList.length>0){
                for (int i = 0; i < tempList.length; i++) {
                    //文件
                    if (tempList[i].isFile()) {
                        subFile.add(tempList[i].toString());
                    }
                    //文件夹
                    if (tempList[i].isDirectory()) {
                        //读取某个文件夹下的所有文件夹
                        System.out.println("文件夹:"+tempList[i]);
                    }
                }
            }
        }
        return subFile;
    }

 

posted on 2017-03-10 16:05  嘣嘣嚓  阅读(1179)  评论(0编辑  收藏  举报

导航