java方法如下:
public String fileRoot(File pf,String filename){
File file = new File(pf+":/");
if(!file.isDirectory()){
return "盘符不存在";
}
if(file.isDirectory()){
File[] file1 = file.listFiles();
for(int i=0;i<file1.length;i++){
if(file1[i].isFile()&&file1[i].getName().equals(filename)){
return file1[i].getAbsolutePath();
}else if(file1[i].isDirectory()){
fileRoot(file1[i],filename);
}else{
System.out.println("文件不存在或者不在此磁盘中");
break;
}
}
}
return "";
}
时间: 2024-11-05 16:09:47