IntelliJ Java IDE
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in File methods Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "doubt in File methods" Watch "doubt in File methods" New topic
Author

doubt in File methods

prasanthi kothapa
Ranch Hand

Joined: Oct 19, 2000
Posts: 30
hi guys,
can anyone explain me this question from one of the mock exams:
What will be the output?

Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
import java.io.*;
public class IO {
public static void main(String args[]) {
File f1 = new File("\\12345.msg");
System.out.println(f1.getPath());
System.out.println(f1.getParent());
System.out.println(f1.isAbsolute());
System.out.println(f1.getName());
System.out.println(f1.exists());
System.out.println(f1.isFile());
}
}
the ans is:
\12345.msg
\
true
12345.msg
false
false

thanks....waiting for your replies.
prasanthi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11862
The key point here is that creating a File object does not create a file. The \12345.msg path does not point to a real file since the file system only has C:\JAVA\12345.msg
Therefore exists() and isFile() return false.
Bill

Java Resources at www.wbrogden.com
prasanthi kothapa
Ranch Hand

Joined: Oct 19, 2000
Posts: 30
Thanks a lot Brodgen.That cleared my doubt.
prasanthi
prasanthi kothapa
Ranch Hand

Joined: Oct 19, 2000
Posts: 30
what about the isAbsolute() method of the File.
why does it give true???
 
IntelliJ Java IDE
 
subject: doubt in File methods
 
Threads others viewed
file path etc...
IO question
getPath()
File Object, Poddar Exam Q: 41
i/o
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com