Languages
[Edit]
EN

Java - file delete

0 points
Created by:
Callen-Payne
384

In this article, we would like to show you how to delete files in Java.

Practical example

import java.io.File;

public class Example {

    public static void main(String[] args) {
        File file = new File("C:\\path\\to\\file.txt");

        if (file.delete()) {
            System.out.println("File deleted.");
        } else {
            System.out.println("Delete failed!");
        }
    }
}

Result:

Java - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join