- 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
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
- Related Articles
- How to check the Existence of a File using C#?
- Check for the existence of a key in Java IdentityHashMap
- Check for the existence of a value in Java IdentityHashMap
- How to check the permissions of a file using Python?
- How to check the Date and time of Access (last modified) of a File using Java?
- Check existence of an element in Java ArrayList
- Check for the existence of key in an object using AngularJS
- How to read the contents of a JSON file using Java?
- How to find the file using Java?
- How to check existence of an element in android listview?
- MongoDB query to check the existence of multiple fields
- How to store the contents of arrays in a file using Java?
- How to check if the file is empty using PowerShell?
- How to check existence of NaN keyword in an array JavaScript
- How to check if a file exists or not in Java?

Advertisements