为什么我要遍历c下的目录的时候总是会出错呢? NullPointerException仔细检查你的代码中的每个变量看看有没有没有实例化就引用的成员变量 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public File myanotherTree(LinkedList myList,int time) { System.out.println("come into my another tree here "); myDir=new File(path); Stack myStack = new Stack(); String str = new String(); myStack.push(myDir); boolean bool; while(!myStack.empty()) { tempdir=(File)myStack.pop(); if(tempdir.isDirectory()) { contents=tempdir.listFiles(); str=String.valueOf(contents.length); for(int i=0; i< contents.length; i++) { myStack.push(contents[i]); } bool=mylist(myList,str); if(!bool){ k=0; bool = true; return tempdir;} } else { bool = changedfile(tempdir,time); if(!bool){ bool= true; k=0; return tempdir;} } } k=0; System.out.println("------------------ Have done ---------------"); return myDir; } public boolean mylist(LinkedList myList,String str) { if(k==myList.size()) { myList.add(str); k+=1; return true; } else if(!str.equals(myList.get(k))){ myList.set(k,str); k+=1; return false; } else { k+=1; return true; } } public boolean changedfile(File tempdir,int time) { long j=tempdir.lastModified(); long p=System.currentTimeMillis(); if((p-j)<3*time) return false; else return true; } 我用一个list把contents的length存放在里面,一旦文件夹中文件数目有改变就返回,同样,如果有文件被修改的话,也会由changedfile返回。谢谢帮偶看看是什么问题? c盘下有个叫 system valume的目录(更准确地说是你的系统盘下)这个目录.listFiles();的时候会得到null. 哦,原来如此,那么怎么样才能解决这个问题呢?用什么可以代替.listFile()吗?谢谢~~~~~ ^^ File[] list = dir.listFile();if( null == list){ break;}我也没有更好的办法。 java中 如何用命令删除数据库中的所有表 java 能不能实现这样的要求,数据先到内存再被调用和保存 最近遇到了很多问题,还请各位大侠过来指点一下!! JDBC将得到的String加入到Object数组中 如何判断一个文件已经生成了?? jar的问题 初学,头回在命令方式下编译,却不能开始 各位GGJJ,紧急求救!字符串比较的问题! 事务问题。 jbuider 中dbSwing的FontChooser在哪里? 树叶 打印两问题
{
System.out.println("come into my another tree here ");
myDir=new File(path);
Stack myStack = new Stack();
String str = new String();
myStack.push(myDir);
boolean bool;
while(!myStack.empty())
{
tempdir=(File)myStack.pop();
if(tempdir.isDirectory())
{
contents=tempdir.listFiles();
str=String.valueOf(contents.length);
for(int i=0; i< contents.length; i++)
{
myStack.push(contents[i]);
} bool=mylist(myList,str);
if(!bool){
k=0;
bool = true;
return tempdir;}
}
else
{
bool = changedfile(tempdir,time);
if(!bool){ bool= true; k=0; return tempdir;}
}
}
k=0;
System.out.println("------------------ Have done ---------------");
return myDir;
}
public boolean mylist(LinkedList myList,String str)
{
if(k==myList.size())
{
myList.add(str); k+=1;
return true;
}
else if(!str.equals(myList.get(k))){
myList.set(k,str);
k+=1;
return false;
}
else {
k+=1;
return true;
}
}
public boolean changedfile(File tempdir,int time)
{
long j=tempdir.lastModified();
long p=System.currentTimeMillis();
if((p-j)<3*time)
return false;
else return true;
}
我用一个list把contents的length存放在里面,一旦文件夹中文件数目有改变就返回,同样,如果有文件被修改的话,也会由changedfile返回。谢谢帮偶看看是什么问题?
用什么可以代替.listFile()吗?
谢谢~~~~~ ^^
if( null == list)
{
break;
}我也没有更好的办法。