This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I/O K&B Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I/O K&B Question" Watch "I/O K&B Question" New topic
Author

I/O K&B Question

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
This is the self test question of K&B.

I did not under stand the question or the answer what it means.
Tried looking at the API but didn't help either.
Can some one please explalin what's going on?




And the invocation is
java Directores file2.txt

is issued from a directory that has two subdirectories "dir1" and "dir2" and that "dir1" has a file "file1.txt" and "dir2" has a file "file2.txt",
and the out put is :
false true

Which set of code fragments must be inserted?


1. String path=d;
System.out.println(file.exists() + " ");

2. String path=d;
System.out.println(file.isFile() + " ");

3. String path=File.separator + d;
System.out.println(file.exists() + " ");

4. String path=File.separator + d;
System.out.println(file.isFile() + " ");


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
sharad sinha
Greenhorn

Joined: Jul 13, 2008
Posts: 26

options 1 and 2 are correct. what is the problem?
You are already inside the directory from where the command is invoked.
In the first for loop file2.txt will not be found in dir1 and will be found in dir2.
In the second for loop file2.txt is not a file inside dir1 but is a file inside dir2.


Thanks, Sharad<br />SCJP 5 (July, 2008)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I/O K&B Question