!!!我写的一个在搜索硬盘上的文件的软件为什么在搜索ntfs格式的时候会出现nullpointer错误,而fat32的不会 不是很清楚,是不是安全问题呢?不过按理说不应该的,因为JAVA不在乎硬盘的存储方式的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 应该不会吧?我做的拷贝目录的函数,NTFS格式的目录也可以考得. 我的怎么会呢,看看我的代源,请你们看看有什么问题public void search(String path) { file=new File(path); String[] strlist; strlist=file.list(); for(int i=0;i<strlist.length;i++) { childpath=path+"\\"+strlist[i]; childfile=new File(childpath); if(childfile.isDirectory()) { search(childpath); } else // else{filename=childfile.getAbsolutePath(); { filename=childfile.getAbsolutePath(); //System.out.println(childfile.getAbsolutePath()+filename); try{if(filename.endsWith(".mp3")) {num++; toClient.println(num+" "+filename+"<br>"); toClient.flush(); } //f.write((Integer.valueOf("\n")).intValue()); }catch(Exception e){} } }}} for(int i=0;i<strlist.length;i++) { System.out.println(strlist[i]);//加上看看什么问题 childpath=path+"\\"+strlist[i]; childfile=new File(childpath); if(childfile.isDirectory()) { search(childpath); } else // else{filename=childfile.getAbsolutePath(); { filename=childfile.getAbsolutePath(); //System.out.println(childfile.getAbsolutePath()+filename); 明白了,原来是磁盘里有个System Volume Information的文件夹不能访问才出现的这个问题,不知道为什么这个文件夹不能访问,有人知道吗? 这个是windows的系统文件,描述磁盘本身信息 呵呵,我告诉你怎么做,你检查一下是不是hidden,也就是说你在if(childfile.isDirectory()&&childfile.isHidden())这样就可以了,而且你要知道别人也不希望你的软件可以搜寻hidden的东西! java中的很多问题都没有得到很好的解决,比如以上问题。希望新版java能够妥善解决好许多兼容性的问题。毕竟很多人都是基于Windows开发的。 System Volume Information 是系统文件夹,好像是 NTFS 权限管理 起了限制左右 ,你不能读取文件,好像只能列举文件 (用 Administrator 账户都这样。). 它属于 System 账户。 一道java面试题目,估计n多人都不会做!用java语言写一段代码,要求计算出一个二叉树单节点(只有一个孩子的节点)的个数. 求递归算法 基于udp的socket通信的数据接收问题? 如何让TextField里的内容不可见 难道说socket就不能做webim吗? 请教大家.关于统计不同单词的问题 通过鼠标获取屏幕上的单词。 何为bad smell? 关于cloudscape数据库的问题 编译.java文件,出现“找不到符号”的错误 一个return的小问题! 关于jdbc方面的--------------急 大哥帮我
public void search(String path)
{
file=new File(path);
String[] strlist;
strlist=file.list();
for(int i=0;i<strlist.length;i++)
{
childpath=path+"\\"+strlist[i];
childfile=new File(childpath);
if(childfile.isDirectory())
{
search(childpath);
}
else
// else{filename=childfile.getAbsolutePath();
{
filename=childfile.getAbsolutePath();
//System.out.println(childfile.getAbsolutePath()+filename);
try{if(filename.endsWith(".mp3"))
{num++;
toClient.println(num+" "+filename+"<br>");
toClient.flush(); }
//f.write((Integer.valueOf("\n")).intValue());
}catch(Exception e){}
}
}
}
}
{
System.out.println(strlist[i]);//加上看看什么问题
childpath=path+"\\"+strlist[i];
childfile=new File(childpath);
if(childfile.isDirectory())
{
search(childpath);
}
else
// else{filename=childfile.getAbsolutePath();
{
filename=childfile.getAbsolutePath();
//System.out.println(childfile.getAbsolutePath()+filename);
希望新版java能够妥善解决好许多兼容性的问题。
毕竟很多人都是基于Windows开发的。