How to delete a file using Java

Configurare noua (How To)

Situatie

To delete a file in Java, use the delete() method:

Solutie

import java.io.File; 

public class DeleteFile {
  public static void main(String[] args) { 
    File myObj = new File("test.txt"); 
    if (myObj.delete()) { 
      System.out.println("Deleted the file: " + myObj.getName());
    } else {
      System.out.println("Failed to delete the file.");
    } 
  } 
}

Tip solutie

Permanent

Voteaza

(2 din 8 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?