![](/img/trans.png)
[英]How to delete a specific File/Folder from a jar pragmatically in java
[英]How to delete specific file from folder in JAVA, without deleting the folder itself?
我在刪除文件夾中的特定文件時遇到問題,這就是我想發生的事情:
我想刪除一個文件,其文件名為..
這是我的代碼:
try
{
File f=new File("C://Generated Barcodes//"+file_copy.getText()+".png");//full path like c:/home/ri
if(!f.exists())
{
JOptionPane.showMessageDialog(null, "Something Went Wrong!",
" ", JOptionPane.ERROR_MESSAGE);
}
else
{
f.delete();
}
} catch(Exception e) {
e.printStackTrace();
}
誰能幫我解決這個問題。 它實際上並沒有刪除文件。 而且我猜想,那里的delete()沒有任何作用。 非常感謝您的幫助。
你為什么要檢查存在性? 只需嘗試刪除,然后趕上警報。 將錯誤消息放入陷阱中。
try
{
File f=new File("C:/Generated Barcodes/" + file_copy.getText() + ".png");
boolean deleted = f.delete();
} catch(Exception e) {
JOptionPane.showMessageDialog(null, "Something Went Wrong!",
" ", JOptionPane.ERROR_MESSAGE);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.