前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >java获取指定文件夹下的所有文件名

java获取指定文件夹下的所有文件名

作者头像
bear_fish
发布2018-09-19 16:01:58
发布2018-09-19 16:01:58
2.8K0
举报

http://blog.csdn.net/tomorrowzm/article/details/3693653

  1. package Test;    
  2. import java.io.File;    
  3. /** 
  4.  * @author yinxm 
  5.  * @version 1.0 2005/06/17 
  6.  *  
  7.  * This class can take file's path and file's name; 
  8.  * you must give the path where you want to take the file. 
  9.  */
  10. public class TakeFilePathAndName {    
  11. public static void main(String[] args) {   
  12. // This is the path where the file's name you want to take. 
  13.         String path = "C://Documents and Settings//yinxm//デスクトップ//TestFile";   
  14.         getFile(path);   
  15.     }   
  16. private static void getFile(String path){   
  17. // get file list where the path has 
  18.         File file = new File(path);   
  19. // get the folder list 
  20.         File[] array = file.listFiles();   
  21. for(int i=0;i<array.length;i++){   
  22. if(array[i].isFile()){   
  23. // only take file name 
  24.                 System.out.println("^^^^^" + array[i].getName());   
  25. // take file path and name 
  26.                 System.out.println("#####" + array[i]);   
  27. // take file path and name 
  28.                 System.out.println("*****" + array[i].getPath());   
  29.             }else if(array[i].isDirectory()){   
  30.                 getFile(array[i].getPath());   
  31.             }   
  32.         }   
  33.     }   
  34. }   
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年08月04日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档