Saturday, August 2, 2008

Program to check if a file exists or not

It would be always nice to check that if a file exists or not if you are going to take a file as input. Find below a code snippet for this:


package com.milestone.snippets;

import java.io.File;

/**
* @author AARYA
*
*/
public class FileExistaOrNot
{
/**
* @param args
*/
public static void main(String[] args)
{
boolean exists = (new File("inputfile.txt")).exists();
if (exists)
{
System.out.println("The File Exists");
} else
{
System.out.println("The File Doesnt Exist");
}
}
}


0 comments: