No Checking

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

The file notLikely.txt Does Not exist.

No Checking

The constructor does not throw IOExceptions. No checking is done of the path name. Here is the example program, slighlty improved:

import java.io.*;
class TestExist
{

  public static void main ( String[] args ) 
  {
    String pathName;
    
    if ( args.length == 1 ) 
      pathName = args[0];
    else
      pathName = "";

    File   test = new File( pathName );

    if ( test.exists() )
      System.out.println( "The file " + pathName + " exists." );
    else
      System.out.println( "The file " + pathName + " Does Not exist." );
  }

}

Try running it with a variety of arguments on the command line, both files and directories. Here are some examples:

C:/cai/cs151/Notes/chap87/programs>java  TestExist TestExist.java
The file TestExist.java exists.

C:/cai/cs151/Notes/chap87/programs>java  TestExist ../programs/TestExist.java
The file ../programs/TestExist.java exists.

C:/cai/cs151/Notes/chap87/programs>java  TestExist ../programs
The file ../programs exists.

C:/cai/cs151/Notes/chap87/programs>java  TestExist C:/cai/cs151
The file C:/cai/cs151 exists.

C:/cai/cs151/Notes/chap87/programs>java  TestExist C:/glarch.txt
The file C:/glarch.txt Does Not exist.

Some of these arguments are relative path names, others are absolute pathnames. Some are directory names.

QUESTION 5:

Is "C:/cai/cs151" a relative or an absolute path name?