大家好,我使用commons-upload做上传,我想把上传的文件(sfile)复制一份然后把原来上传的文件删除掉,但是用sfile.delete()总是无法删除sfile,请问应该怎么做,或者还有别的方法么,谢谢,谢谢~File sfile = new File(tempFileName);
fi.write(sfile);
File file = new File(filename);
FileInputStream sfis = new FileInputStream(sfile);
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int sfileBuf = 0;
while ((sfileBuf = sfis.read(buf)) != -1) {
fos.write(buf, 0, sfileBuf);
}
fos.close();
sfis.close();
//删除原文件
sfile.delete();
fi.write(sfile);
File file = new File(filename);
FileInputStream sfis = new FileInputStream(sfile);
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int sfileBuf = 0;
while ((sfileBuf = sfis.read(buf)) != -1) {
fos.write(buf, 0, sfileBuf);
}
fos.close();
sfis.close();
//删除原文件
sfile.delete();
解决方案 »
- struts2的Datetimepicker 提示java.text.ParseException: Unparseable date: ""
- jsp分页中的上一页,下一页到最边界后怎样使他们无效
- 时间之间的检索SQL文
- tomcat编译部署servlet的问题?
- 解析[fly][color=YellowGreen]你好[/color][/fly]
- [求助]连接非本机sql2005数据库的基础条件是哪些啊?
- 在JSP中能不能自定义打印区域
- 我做一个人事管理系统,能够实现删除,插入,修改,查询,下面是我的代码,通过了编译,就是运行不了,请大家帮帮我
- 高分求助,在网页上显示存储在磁盘上的图形文件,如何成比例控制图形的大小
- 运行了jbuilder6.0中的.jsp文件后,我的tomcat出问题了
- 文件上传得问题,麻烦大家了
- javascript中的问题
public static void delAllFile(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
String dirPath = null;
if(fileList != null) {
for(int i = 0 ; i < fileList.length; i++) {
if(fileList[i].isFile()) {
fileList[i].delete();
}
if(fileList[i].isDirectory()){
dirPath = fileList[i].getPath();
delAllFile(dirPath);
}
}
file.delete();
}
}递归删除..