java IO 获取文件父级路径 ,如果为空则执行删除

file1=new File(path);//path 为文件地址绝对路径
//File ff = new File(file.getAbsolutePath());相对路径获取方法
//String copyPath = ff.getParentFile().getParent();
String parentPath=file1.getParent();parentPath为path的父级目录地址
String[] arr=null;//用来验证文件是否为空文件
File parentFile=new File(parentPath);
if(parentFile.isDirectory()){
arr= parentFile.list();
}
if(arr.length==0){

parentFile.delete();//删除文件
}
posted @ 2021-07-02 10:13  晓*雨  阅读(195)  评论(0)    收藏  举报