天天看點

java讀取檔案夾檔案及操作

 public static File[] listFile(String path)

 {

  File f = null;

  // 建立檔案執行個體

  f = new File(path);

  // 此處擷取檔案夾下的所有檔案

  File[] list = f.listFiles();

  return list;

 }

 public static void move(String frompath,String topath,String topathname)

 {

  // 如果目标檔案夾不存在,建立新的日期檔案夾

    if (!(new File(topath).exists())) {

     new File(topath).mkdir();

    }

    File from = new File(frompath);

     File to = new File(topathname);

     from.renameTo(to);

 }

 public static void main(String[] args)

 {

  File[] list=listFile("D:\\cert");

  for (int i = 0; i < list.length; i++)

  {

   System.out.println(list[i].getAbsolutePath());

  }

 }

繼續閱讀