title: java program which delete file and recover it
body: <p>This is my code to delete '.txt' files from specific folder(/home/user). But once it is deleted I don't know how to recover these deleted files.</p>
  
  <p>Please show me some example code (if possible), to achieve this.</p>
  
  <p>Is it possible in java? If so then please help me (I am happy to use any other language.)</p>
  
  <pre><code>import java.*;
  import java.io.File;
  class  CountFiles
  {
      public static void main(String args[])
      {
          String dirPath="/home/user";
          File f = new File(dirPath);
          File[] files = f.listFiles();
          int s=files.length;
          System.out.println("Number of files in folder "+s);
          for(int i=0;i &lt;s; i++)
          {
              if (files[i].isFile())
              {
                  String FilesName = files[i].getName();
                  System.out.println(FilesName);
                  if (FilesName.endsWith(".txt") || FilesName.endsWith(".TXT"))
                  {
                      boolean success = files[i].delete();
                      vif (!success) throw new IllegalArgumentException("Delete: deletion failed");
                      else System.out.println("file deleted");
                  }
                  System.out.println("file deleted out side.....");
              }
          }
      }
  }
  </code></pre>