Pages Navigation Menu

Coding is much easier than you think

How to delete file if exists in java?

How to delete file if exists in java?




public class FileDemo {
   public static void main(String[] args) {
        String tempFile = "C:/mydir/myfile.txt";
        //Delete if tempFile exists
        File fileTemp = new File(tempFile);
          if (fileTemp.exists()){
      }catch(Exception e){
         // if any error occurs

About Mohaideen Jamil

Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.