public class dirlist {
    public static void main(String[] args) {
        File path= new File(".");
        String [] list=path.list();
        
        for (int i=0;i<list.length;i++)
        System.out.print(list[i]+" ");
}
此程序是当前路径下文件名输出,但怎么样去访问其他盘的其他路径呢?应该怎么改?

解决方案 »

  1.   

    答:如访问在d:/下内容,则参考代码如下:import java.io.*; public class dirlist { 
        public static void main(String[] args) { 
            File path= new File("d:/"); 
            File[] list=path.listFiles();
             
            for (int i=0;i <list.length;i++) 
            System.out.println(list[i]+" "); 

    }
      

  2.   

    File path= new File("D:\\"); //这里写你要去的绝对路径!
      

  3.   

    "d:/" is also an absolute path.