に動作していないことはここでは、コードの他の部分に行くpdfファイル単純なファイルは、Java
try {
File file = new File(docObjectId + ".pdf");
file.setWritable(true);
System.out.println(file.length());
if (file.delete()) {
System.out.println(file.getName() + " is deleted!");
} else {
System.out.println("Delete operation is failed.");
}
} catch (Exception e) {
e.printStackTrace();
}
を削除する私のコードです。
PDFファイルはプロジェクトのルートフォルダにあり、手動で削除することができます。今、私の頭を掻く。
完全な方法です。それは例外では正確でないかもしれません
try {
file.delete();
System.out.println("file deleted");
} catch(IOException e) {
System.out.println("file not deleted");
}
に他の何らかの理由
public Response getContractDocument(@PathParam("docid") String docObjectId) throws Exception {
DocumentumService documentumService = new DocumentumService(documentumConfigUtil);
DocumentumDocumentBean docDocumentBean = documentumService.getContractDocContent(docObjectId, true);
FileInputStream fileInputStream;
fileInputStream = new FileInputStream(docDocumentBean.getDocFile());
compressPdf(fileInputStream,docObjectId + ".pdf");
fileInputStream = new FileInputStream(docObjectId + ".pdf");
ResponseBuilder responseBuilder = Response.ok((Object) fileInputStream);
try {
File file = new File(docObjectId + ".pdf");
System.out.println(file.getAbsolutePath());
file.setWritable(true);
System.out.println(file.length());
File d = new File(file.getAbsolutePath());
if (d.delete()) {
System.out.println(file.getName() + " is deleted!");
} else {
System.out.println("Delete operation is failed.");
}
} catch(Exception e) {
e.printStackTrace();
}
return responseBuilder.build();
}
:あなたが削除しようとする前に
はこれを試してみてください。あなたは文が単に 'ファイル'が削除されているかどうかをチェックしているのです。 – Jixone私の頭の中で最初に浮かぶのは、使用したファイルパスが正しいことですか?相対的な場合は、それがあなたの考えであることを確認することにします。 –
if(file.exists()){ file.delete();これを試してください。 } – Tehmina