- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Deleting a File in java
You can delete a file using the delete() method of the File class.
Program
import java.io.File; public class DeleteFileExample { public static void main(String[] args) { try { File file = new File("myFile"); if(file.delete()) { System.out.println(file.getName() + " is deleted!"); } else { System.out.println("Delete operation is failed."); } catch(Exception e) { e.printStackTrace(); } } }
Output
Delete operation is failed.
- Related Articles
- Copying a File in java
- Reading a Text file in java
- Create a temporary file in Java
- Deleting a Label in Python Tkinter
- How to truncate a file in Java?
- Create a new empty file in Java
- How to compress a file in Java?
- File Permissions in java
- File Objects in Java
- Check whether a file is a directory in Java
- How to create a pdf file in Java?
- Check if a file exists in Java\n
- Writing a CSV file in Java using OpenCSV
- Change a file attribute to writable in Java
- Get Absolute path of a file in Java

Advertisements