- 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
How to check the Existence of a File using Java?
The file class provides a method named exists() which returns true if the file specified in the current file object exists.
Example
import java.io.File; public class FileHandling { public static void main(String args[]) { File file = new File("samplefile"); if(file.exists()) { System.out.println("Given file existed"); } else { System.out.println("Given file does not existed"); } } }
Output
Given file does not existed
Advertisements