读取文件夹中的文件列表

来源:互联网 发布:java 超时异常 编辑:程序博客网 时间:2024/05/19 18:16

 import java.io.*;

public class myapp
{
  public static void main(String args[])  throws IOException
  {
   boolean Flag=false;
   String pathname="F://my video//Prison Break S4";
     File myfile=new File(pathname);
  if(myfile.exists()==false)
     Flag= myfile.createNewFile();
  else
      System.out.println("文件已经存在!");
     if(Flag==true)
       System.out.println("已经新建文件!文件路径为:");
       String filelist[];
       filelist=new String[20];
       filelist=myfile.list();
       for(int i=0;i<filelist.length-1;i++)
   System.out.println(filelist[i]);
   }
  
}