public class solution { 
	public static void main(String args[]) 
	{ 

		// Get the file 
		File f = new File("F:\\program.txt"); 

		// Check if the specified file 
		// Exists or not 
		if (f.exists()) 
			System.out.println("Exists"); 
		else
			System.out.println("Does not Exists"); 
	} 
} 

        

public class FileDemo {
   public static void main(String[] args) {      
      File f = null;
      boolean bool = false;
      
      try {
         // create new files
         f = new File("test.txt");
         
         // create new file in the system
         f.createNewFile();
         
         // tests if file exists
         bool = f.exists();
         
         // prints
         System.out.println("File exists: "+bool);
         
         if(bool == true) {
            // delete() invoked
            f.delete();
            System.out.println("delete() invoked");
         }
         
         // tests if file exists
         bool = f.exists();
         
         // prints
         System.out.print("File exists: "+bool);
         
      } catch(Exception e) {
         // if any error occurs
         e.printStackTrace();
      }
   }
}

        

public class JavaFileDirectoryExistsExample
{
  public static void main(String[] args)
  {
    // test "/var/tmp" directory
    File tmpDir = new File("/var/tmp");
    boolean exists = tmpDir.exists();
    if (exists) System.out.println("/var/tmp exists");
    
    if (tmpDir.isDirectory()) System.out.println("/var/tmp is a directory");

    // test to see if a file exists
    File file = new File("/Users/al/.bash_history");
    exists = file.exists();
    if (file.exists() && file.isFile())
    {
      System.out.println("file exists, and it is a file");
    }
  }
}

        

public class FileExistsExample {

	public static void main(String[] args) {

		// initialize File object
		File file = new File("C:\\javatutorialhq\\input\\test_file.txt");

		boolean result;
		//
		result=file.exists();
		if(result){
			// if file exists, read the contents
			System.out.println("File exists... reading the contents");
			Scanner s;
			try {
				s = new Scanner(file);
				//print the contents of the file
				while(s.hasNextLine()){
					System.out.println(s.nextLine());
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			
		}
		else{
			//print message that the file does not exist
			System.out.println("File does not exists");
		}
	}
}

        

public class TemporaryFileExample
{
   public static void main(String[] args)
   {
      File temp;
      try
      {
         temp = File.createTempFile("myTempFile", ".txt");
          
         boolean exists = temp.exists();
          
         System.out.println("Temp file exists : " + exists);
      } catch (IOException e)
      {
         e.printStackTrace();
      }
   }
}

        

public SmallObjectHeap(final String p_memDumpFile, final Storage p_memory) {
    m_memory = p_memory;

    File file = new File(p_memDumpFile);

    if (!file.exists()) {
        throw new MemoryRuntimeException("Cannot create heap from mem dump " + p_memDumpFile + ": file does not exist");
    }

    RandomAccessFileImExporter importer;
    try {
        importer = new RandomAccessFileImExporter(file);
    } catch (final FileNotFoundException e) {
        // cannot happen
        throw new MemoryRuntimeException("Illegal state", e);
    }

    importer.importObject(this);
}

        

public static boolean mkdirsWithExistsCheck(File dir) {
  if (dir.mkdir() || dir.exists()) {
    return true;
  }
  File canonDir = null;
  try {
    canonDir = dir.getCanonicalFile();
  } catch (IOException e) {
    return false;
  }
  String parent = canonDir.getParent();
  return (parent != null) && 
         (mkdirsWithExistsCheck(new File(parent)) &&
                                    (canonDir.mkdir() || canonDir.exists()));
}

        

private void processSubFiles(File file, ProcessSubAIDLFileCallback callback) {
    if (file == null) {
        return;
    }
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null && files.length > 0) {
            for (File f : files) {
                processSubFiles(f, callback);
            }
        }
    } else {
        if (callback.matchFile(file)) {
            callback.processFile(file);
        }
    }
}

        

private void doTestUnpackWAR(boolean unpackWARs, boolean unpackWAR,
        boolean external, boolean resultDir) throws Exception {

    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();

    host.setUnpackWARs(unpackWARs);

    tomcat.start();

    File war;
    if (unpackWAR) {
        war = createWar(WAR_XML_UNPACKWAR_TRUE_SOURCE, !external);
    } else {
        war = createWar(WAR_XML_UNPACKWAR_FALSE_SOURCE, !external);
    }
    if (external) {
        createXmlInConfigBaseForExternal(war);
    }

    host.backgroundProcess();

    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    Assert.assertEquals(
            Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}

        

public synchronized static boolean setOfflineFilePath( String newPath )
{
	if ( !newPath.endsWith( "/" ) )
	{
		newPath = newPath + "/";
	}

	File newTarget = new File( newPath );

	if ( !newTarget.exists() || !newTarget.isDirectory() )
	{
		return false;
	}

	OFFLINE_FILE_PATH = newPath;

	return true;
}        
main