-1

İf İ deleted files consider the below code.
May samebody can recovery this deleted files?
If yes, how can I prevent this operation?
Thanks in advance!

File file = new File(input.nextLine());
for (File f : file.listFiles()) { 
    f.delete();
}

or

FileUtils.cleanDirectory(file);
shiftpsh
  • 1,926
  • 17
  • 24
MehmanBashirov
  • 641
  • 1
  • 7
  • 15

1 Answers1

0

Your above code will delete files but it would be recoverable because of the working of file system.

Concept: When the file is requested to be deleted, the OS does not remove the content of entire file because of performance reasons. OS perform these tasks:

  • removes the file pointer (stored in MFT)
  • OS announces reserved space as free of that specific file/folder

As suggested by @ernest_k, the only way to remove data is shredding except physical destruction.

If you are writing a program to do this task then your program should:

  1. Open a file
  2. Read it's content
  3. Generate random data
  4. Replace it with the original content
  5. At the end, you can remove the file

For multiple passes, you can repeat the above steps. I don't exactly remember but different standards are recommended in different standards like 1-pass, 3-pass, 6-pass.

Hope it helps! :)

Atlas_Gondal
  • 2,512
  • 2
  • 15
  • 25
  • 1
    [Overwriting a file is a very, very unreliable way of making sure the data in it can not be recovered.](https://stackoverflow.com/questions/913282/shred-doesnt-work-on-journaled-fs) – Andrew Henle Aug 02 '18 at 15:09
  • @AndrewHenle thanks for pointing out but I guess this is the only way to make it unrecoverable with the exception of physical destruction. If we read raw bytes from a file and write random bytes in that file, then it is highly likely that file will not be recoverable. However, we cannot guarantee. I'm not aware of any other way, if you do then please share with us! :) – Atlas_Gondal Aug 02 '18 at 15:49
  • 1
    You appear to assume OP is running Windows which may not be the case. – Mark Setchell Aug 12 '18 at 20:21
  • @MarkSetchell You are right, but I did not specify any code. I've shared the concept which is valid for all OS's. – Atlas_Gondal Aug 13 '18 at 01:59