方法一:利用java中的文件delete方法
ps:路徑一定是//!!!!!!eg://tmp//linuxup//刪除的文件名
localPath = "/tmp";
File delfile = new File("//tmp"+good.getGpictureid().replace("linuxup","/"));
// 路徑爲文件且不爲空則進行刪除
System.out.println("---刪除"+delfile.isFile()+delfile.exists());
if (delfile.isFile() && delfile.exists()) {
delfile.delete();
System.out.println("---刪除源文件成功");
}
方法二:利用linux中的終端命令
String path = "/tmp"+gplist.get(0).getGpic().replace("linuxup","");//文件夾路徑
System.out.println("刪除路徑"+path);
try{
// Runtime.getRuntime().exec("su *******");//用於轉換權限
Process process = Runtime.getRuntime().exec("rm -f"+path);
System.out.println("刪除成功");
}catch(IOException e){
e.printStackTrace();
}