处理上传图片的临时文件代码

来源:互联网 发布:抢票软件演唱会 编辑:程序博客网 时间:2024/06/10 03:23
//删除文件
public static boolean deleteFile(String sPath){

boolean flag=false;
File file=new File(sPath);
if(!file.exists()){
return flag;
}
if(!file.isDirectory()){
return flag;
}
String[] tempList=file.list();
File temp=null;
for (String string : tempList) {
if(sPath.endsWith(File.separator)){
temp=new File(sPath+string);
}else{
temp=new File(sPath+File.separator+string);
}
if(temp.isFile()){
temp.delete();
}if(temp.isDirectory()){
deleteFile(sPath+"/"+string);
flag=true;
}
}
/*if(file.isFile() && file.exists()){

file.delete();
flag=true;
}else if(file.isDirectory()){
String[] filelist=file.list();
for(int i=0;i<filelist.length;i++){
File delfile=new File(sPath+"\\"+filelist[i]);
if(!delfile.isDirectory()){
delfile.delete();
}else{deleteFile(sPath+"\\"+filelist[i]);}
}
}*/
return flag;
}
0 0