!!!我写的一个在搜索硬盘上的文件的软件为什么在搜索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新手求解 求高手指教 在JPanel中绘制图片周围出现黑框 ?怎么解决啊 添加代码 为什么我JPanel设置不了背景颜色 synth swing jComboBox 及最大化最小化 xml 求线程实例! 伙计做的动网论坛邮件地址收集工具,大家看有什么好的建议? 为什么 compareTo可以直接用,而compare不能? AWT中有没有类似于SWing的标签面板(就是可以切换面板)类呀? 一个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开发的。