处理上传图片的临时文件代码
2017-01-11 11:59
232 查看
//删除文件
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;
}
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;
}
相关文章推荐
- Java Builder Pattern建造者模式详解及实例
- 让IntelliJ IDEA更好用
- C#-Socket编程-UDP
- Struts2--拦截器
- SpringMVC中出现“400 Bad Request错误(参数校验错误)
- JSP页面中的6种Java元素
- 详解Java如何获取文件编码格式
- 内部类访问局部变量的时候,为什么变量必须加上final修饰(转)
- C# t4模版引擎笔记 引入外部dll
- java Date时间格式工具类DateUtil
- Python时间获取及转换知识汇总
- c++11 pod类型(了解)
- springmvc文件上传代码
- Java反射入门
- 设计模式之单例模式-java
- Java 定时器(Timer,TimerTask)详解及实例代码
- json跨域调用python的方法详解
- FineReport中以jws方式调用WebService数据源方案
- JAVA Thread Dumps 三部曲
- python——判断一段音频是否有声音