java删除linux系统中文件

方法一:利用java中的文件delete方法ps:路径一定是!!!!!&#

方法一:利用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();
                }

 

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754877450a5211961.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信