From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch09;
02
03 importimport means to make the classes and/or packages available in this program java.io.File;
04
05 /**
06 * A program which reads its command-line arguments, treating each as
07 * the name of a file. Create an ExistsFile object with the name of the
08 * file. Then check ifif executes the next statement only if the condition in parenthesis evaluates to true the file exists.
09 *
10 * @authorthis is the Javadoc tag for documenting who created the source code blad
11 */
12 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects ExistsFile {open braces start code blocks and must be matched with a close brace
13 /** Java reference attached to file on file system */
14 File file;
15
16 /**
17 * Create a newnew is used to create objects by calling the constructor ExistsFile with the file pointed to the named file.
18 *
19 * @paramthis is the Javadoc tag for documenting the purpose of parameters fname the name of the file to connect to; the named file
20 * need not exist (it will be checked in exists()).
21 */
22 publicpublic is used to indicate unrestricted access (any other class can have access) ExistsFile(String fname) {open braces start code blocks and must be matched with a close brace
23 file =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor File(fname);
24 }close braces end code blocks and must match an earlier open brace
25
26 /**
27 * Check ifif executes the next statement only if the condition in parenthesis evaluates to true the file exists, printing an appropriate message.
28 */
29 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value exists() {open braces start code blocks and must be matched with a close brace
30 ifif executes the next statement only if the condition in parenthesis evaluates to true (file.exists()) {open braces start code blocks and must be matched with a close brace
31 System.out.println("\"" +adds two numbers together or concatenates Strings together file.getName() +adds two numbers together or concatenates Strings together "\" is a file.");
32 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
33 System.out.println("\"" +adds two numbers together or concatenates Strings together file.getName() +adds two numbers together or concatenates Strings together "\" is NOT a file.");
34 }close braces end code blocks and must match an earlier open brace
35 }close braces end code blocks and must match an earlier open brace
36
37 /**
38 * The arguments are assumed to be the names of files. Each is opened
39 * and echoed to the screen.
40 *
41 * @paramthis is the Javadoc tag for documenting the purpose of parameters args command-line arguments; should name files to be
42 * checked forfor is a looping structure for repeatedly executing a block of code existence
43 */
44 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args) {open braces start code blocks and must be matched with a close brace
45 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer argNdx =this assignment operator makes the left side equal to the right side 0; argNdx !=this is the not equals operator which evaluates to true if both sides are different args.length; ++this is the increment operator, which increases the variable by 1argNdx) {open braces start code blocks and must be matched with a close brace
46 ExistsFile nextFile =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ExistsFile(args[brackets are typically used to declare, initialize and index (indicate which element of) arraysargNdx]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
47 nextFile.exists();
48 }close braces end code blocks and must match an earlier open brace
49 }close braces end code blocks and must match an earlier open brace
50 }close braces end code blocks and must match an earlier open brace
51
52 //Uploaded on Mon Mar 29 21:39:28 EDT 2010
|
Download/View scg/ch09/ExistsFile.java