how-to

File & Directory

How to check if file exists

For working with files, first add to your application java.io.* package:

import java.io.*;

For checking if file exists, use function java.io.File.exists():

if ( new File( "c:\\test.txt" ).exists() ) System.out.print( "File exists" );