请问以下代码有什么问题,,运行时发生NullPointerException
import java.io.*;
class FileDemo5
{
public static void main(String[] args)
{ File dir = new File("d:\\");
method(dir,0);
}
public static String getLevel(int level)
{
StringBuilder sb = new StringBuilder();
sb.append("|--");
for (int x=0;x<level;x++)
{
sb.insert(0," ");
}
return sb.toString();
}
public static void method(File dir,int level)
{
System.out.println(dir);
level++;
File[] fames = dir.listFiles();
for (int x=0;x<fames.length;x++)
{
if(fames[x].isDirectory())
method(fames[x],level);
else
System.out.println(getLevel(level)+fames[x].getName());
}
}
}
|
|