how-to

File & Directory

How to delete file

For working with files you need to use:

import java.io.*;

For file deleting use use function java.io.File.delete(). It is important to have system right for file deleting.

File f = new File( "c:\\test.txt" );
if ( f.exists() ) {
  try {
    f.delete();
  }
  catch ( Exception ex ) {
    // here check exception
  }
}