获取指定文件夹下的内容

来源:互联网 发布:android软件源代码 编辑:程序博客网 时间:2024/04/27 16:32
package FileView;


import java.io.File;


public class FileViewer {


public static void main(String[] args) {   
        // This is the path where the file's name you want to take.   
        String path = "E:\\Read";   
        getFile(path);   
    }   
       
    private static void getFile(String path){   
        // get file list where the path has   
        File file = new File(path);   
        // get the folder list   
        File[] array = file.listFiles();   
          
        for(int i=0;i<array.length;i++){   
            if(array[i].isFile()){   
                // only take file name   
                System.out.println("^^^^^" + array[i].getName());   
                // take file path and name   
                System.out.println("#####" + array[i]);   
                // take file path and name   
                System.out.println("*****" + array[i].getPath());   
            }else if(array[i].isDirectory()){   
                getFile(array[i].getPath());   
            }   
        }   
    }   




}
0 0
原创粉丝点击