路径:/webroot/attached//file/2016-09-30/1475203009564.rar
String clPath = service.getClPath(model);//获取相对路径if(clPath!=null){
String folder1 = (clPath).substring(clPath.indexOf("/")+1,clPath.lastIndexOf("/")+1);//截除第一个’/’,因不同项目名称不一样, ‘zftal-web/attached//file/2016-09-30/’
String folder = (folder1).substring(folder1.indexOf("/"),folder1.length());//’/attached//file/2016-09-30/’
String fileName = (clPath).substring(clPath.lastIndexOf("/")+1);//获取文件名 ‘1475203009564.rar’
String filePath = ServletActionContext.getServletContext().getRealPath(folder);//获取文件夹绝对路径 ‘E:\Workspace_byzs\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\zftal-byzs\attached\file\2016-09-30’
String allPath = filePath + "/" + fileName;//文件完整路径 ‘E:\Workspace_byzs\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\zftal-byzs\attached\file\2016-09-30/1475203009564.rar’
String newPath = allPath.replace("\\", "/");//要删除的文件 ‘E:/Workspace_byzs/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/zftal-byzs/attached/file/2016-09-30/1475203009564.rar’
String realPath = newPath.replace("/", "\\\\");//最终删除路径 ‘E:\\Workspace_byzs\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\zftal-byzs\\attached\\file\\2016-09-30\\1475203009564.rar’
File file = new File(realPath);
boolean b = false;
if(file.exists()){
b = file.delete();//执行删除
}
if(b){
boolean flag= service.scCl(model);//删除文件后删除数据
}