首页 新闻 会员 周边

java代码

0
[待解决问题]

package P2;

public class TestFile
{
public static void main(String[] args)
{
{
// TODO Auto-generated method stub
Showtest test=new Showtest ();
test.Showlist("E:\\程序设计");
}
}
}

 

package P2;
import java.io.File;
public class Showtest
{
static int counter=0;
/*
* 定义一个遍历方法 Showlist,查找目录下的每一个文件或目录将其打印出
*/
void Showlist(String dir)
{
File f=new File(dir);
File f1[]=f.listFiles();
for(int i=0;i<f1.length;i++)
{
counter++;
if(f1[i].isDirectory())
{
System.out.print("<");
System.out.print(f1[i].getName() );
System.out.println(">");
Showlist(f1[i].getName());
}
if(f1[i].isFile())
{
for(;counter>0;counter--)
{
System.out.print(" ");
}
System.out.println(f1[i].getName());
}
}
}
}

晨夕月影的主页 晨夕月影 | 初学一级 | 园豆:186
提问于:2015-11-08 16:51
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册