Sample Programs

Sample java program to delete file

 package org.jusfortechies.example; 

 import java.io.File;

 public class DeleteFile {

   public static void main(String[] args) {

     String strFilePath = "C:\\samplefile.txt";

     File f1 = new File(strFilePath);
     boolean success = f1.delete();

     if (!success) {
       System.out.println("Deletion failed.");
     } else {
       System.out.println("File deleted successfully.");
     }

   }

 }



blog comments powered by Disqus