Check if file exists with java



User Rating:  / 3
PoorBest 
Details
Category: Java
Created on Thursday, 15 November 2012 11:31
Last Updated on Thursday, 15 November 2012 11:31
Published on Thursday, 15 November 2012 11:31
Written by Administrator
Hits: 9964

Simple code for check if file exist in java :

View source
package com.developerpages.snippets.core;
 
import java.io.File;
 
public class CheckIfFileExists {
    public static void main(String[] args) {
        File file = new File("file.txt");
        boolean exists = file.exists();
        System.out.println("File " + file.getPath() + " exists: " + exists);
    }
 
}