import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;


public class PrintFile {
	/**
	 * 递归打印父文件夹下所有的子文件的绝对路径名
	 * @param fileName 作为根目录的文件名
	 */
	public void pirntDIR(String fileName){
		File file=new File(fileName);
		File[]list=file.listFiles();//获取当前文件夹中的所有子目录文件返回一个文件集合
		//判断当前文件是否还有子级目录
		if(list!=null&&list.length>=0)
		for(File f:list
			){
			//打印
			System.out.println(f.getAbsolutePath());
			if(null!=f){
				//如果还有则递归下去
				pirntDIR(f.getAbsolutePath());
			}
			//否则跳出循环结束遍历
			else {
				return ;
			}
		}
	}
	public static void main(String[] args) throws UnknownHostException, IOException {
		
		new PrintFile().pirntDIR("C:\\Documents and Settings\\Administrator\\桌面\\test");
	System.out.println(1111);
	}

}
最近下载更多
mjtljx  LV42 2015年6月16日
wgtgt  LV24 2014年1月30日
骑着猪猪去逛街  LV32 2014年1月13日
Yonggang  LV7 2012年11月2日
最代码官方  LV167 2012年10月31日
最近浏览更多
孟凡一  LV2 2022年11月29日
xiaoxiguaforever  LV1 2021年5月25日
jaonsang  LV25 2021年3月8日
spring123spring  LV5 2021年2月17日
zhyp29  LV3 2020年12月18日
luweizhi2020 2020年9月29日
暂无贡献等级
lyd19931203  LV21 2020年6月30日
Gyq灬ming  LV11 2020年6月22日
qw991558639  LV1 2020年6月14日
wei112233  LV15 2020年4月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友