我已经编写了以下代码来合并和删除源文件,但不知何故源文件没有被删除。任何人都可以说明我在这里缺少什么。
public void doDelete(List<String> dID)throws IOException {
String DID=null;
try{
for( ListIterator<String> iterator = dID.listIterator(); iterator.hasNext();)
{
DID= (String) iterator.next();
System.out.println("Deleting PDF" +DID);
File f =new File("E:\\TestFolder"+ "\\" +DID+".pdf");
if (!f.exists()) {
System.err.println("File " + f
+ " not present to begin with!");
return;
}
System.out.println(f.length());
System.out.println(f.getAbsolutePath());
boolean success = f.delete();
if (!success){
System.out.println("Deletion failed.");
}else{
System.out.println("File deleted."+DID);
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}