admin管理员组文章数量:1130349
方法一:利用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();
}
方法一:利用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();
}
版权声明:本文标题:java删除linux系统中文件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754877451a2738205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论