java刪除linux系統中文件

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章