Hi,
Consider the following piece of code and its output:
File is c:\java\12345.msg and the current directory is c:\java
import java.io.*;
public class IO {
public static void main(
String args[]) {
File f1 = new File("\\12345.msg"); //1
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());
}
}
Output:
\12345.msg
\
true
12345.msg
false
false
Also if the line //1 is changed to
File f1=new File(12345.msg);
the output changes to
12345.msg
null
false
12345.msg
true
true
I don't understand why that happens. I think i don't get the \\12345.msg. Does it mean that the path is the current directory?
Let me list out what i understand. Can anyone tell me if anything is wrong?
1. If i just give just the file name as in 12345.msg, it means i have not given the complete path. That is why isAbsolutePath returns false in the second case.
2. getName() will always return only the file name, so there is no confusion there.
3. the results of exists() and isFile() are obvious.
4. Considering the second case, does getPath() and getParent() return information only relative to the current directory?
5. This is the most problematic part for me -- i think if i am clarified in this, everything will be clear -- What does \\12345.msg mean?
------------------
Regards,
Shree